I assume that you have knowledge of C programing language operators and the If.. else statement of c programming. A leap year comes after every 4 years. In the mathematical term, you can say A year which is divisible by 4 except the century years (years which ends with 00).
Program to check entered 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 is:
1 2 |
Enter a year: 2012 2012 is a leap year. |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c program to check leap year, c tutorials, Check Leap Year in C