1 输入年号,判断它是否是闰年。
分析:如果此年号能被400整除,则它是闰年,如果此年号能被4整除,而不能被100整除,则也是闰年,否则不是闰年。
程序:
#include <stdio.h>
void main()
{
unsigned int year, leap;
printf("Enter year:");
scanf("%d", &year);
if (year % 400 == 0)
leap = 1;//是闰年leap为1
else
{
if (year % 4 == 0 && year % 100 != 0)
leap = 1;
else
leap = 0; //不是闰年为0
}
if (leap==1)
printf("%d:is a leap year.", year);
else
printf("%d:is not a leap year.", year);
return 0;
}