C Language Example - Determine Leap Year
The user inputs a year, and determine whether the year is a leap year.
Example
#include <stdio.h>
int main()
{
int year;
printf("Enter a year:");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
// Here if divisible by 400, it 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;
}
Run result:
输入年份: 1990 1990 不是闰other extensions
C Language Examples