Coding Practice

Write a C program to check whether a year is leap year or not

Check a year is leap year or not
Sample Output
Enter a year: 2020

2020 is leap year.

Process returned 0 (0x0)   execution time : 15.009 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int year;
 
    printf("Enter a year: ");
    scanf("%d", &year);
 
    if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
    {
        printf("\n%d is leap year.\n", year);
    }
    else
    {
        printf("\n%d is not leap year.\n", year);
    }
    return 0;
}
Sample Output
Enter a year: 2021

2021 is not leap year.

Process returned 0 (0x0)   execution time : 2.297 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X