C Program to Check Leap Year

In the previous tutorial , I have discussed about linear search program , Program to take password in C ,Factorial program in C,Program to swap two number . Today i will tell you about "C Program to Check Leap Year"?

Below is the C program to check whether input year is a leap year or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
 
int main()
{
    int year;
 
    printf("Enter a year: ");
    scanf("%d",&year);
 
    if(year%4 == 0)
    {
        if( year%100 == 0)
        {
            // year is divisible by 400, hence the year is a leap year
            if ( year%400 == 0)
                printf("%d is a leap year.", year);
            else
                printf("%d is not a leap year.", year);
        }
        else
            printf("%d is a leap year.", year );
    }
    else
        printf("%d is not a leap year.", year);
     
    return 0;
}
Output:

Enter a year: 2001
2001 is not a leap year


I hope you have understand the program. I would like to have feedback from you. Your feedback, question ,queries or comments  are always welcome.

Thanks.
C Program to Check Leap Year C Program to Check Leap Year Reviewed by CodiBucket on 09:40 Rating: 5

No comments:

Powered by Blogger.