Thursday, April 2, 2020

C program to Check leap year

C Program to Check leap year 

#include 
int main()
{
    int year; // integer value  
    printf("Enter a year: "); // enter user value 
    scanf("%d", &year); // storing user value
    if (year % 4 == 0) // check leap year
    {
        if (year % 100 == 0) // 
 {
            // the year is a leap year if it is divisible by 400.
            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 1

Enter a year = 1900
1900 is not leap year

Output 2

Enter a year = 2014
2014 is leap year

Happy coding

0 comments:

Post a Comment

Recent Posts