c-thumb

C Program to print Leap Years between two given years!

In this post, we are going to write a C program to print leap years between two given years.

So basically we need to collect the start year and end year from the user, then we need to loop between the start and end year and then find the leap years to print.

But before if you want to know the formula to find the leap year here it is,

1. A year should be evenly divisible by 4 (should not have a reminder):

    year % 4 == 0 ( reminder should be 0 )

2. AND Year should not be evenly divisible by 100 (should have a reminder):

    year % 100 != 0 ( reminder should not be 0 )

3. OR Year should be evenly divisible by 400 (should have a reminder):

    year%400 == 0 ( reminder should be 0 )

So basically 1 && 2 || 3

if (1  and 2) both are true or 3 is true then it is a leap year

Here is the entire script for you,

Go through the comments in the above program to understand it.

Example output of the above,

Enjoy coding.

 

Related Posts

Leave a Reply