从键盘任意输入一个年号,判断它是否是闰年。已知符合下列条件之一者是闰年:(1)能被4整除,但不能被100整除;(2)能被400整除。
输入提示信息:"Input a year:"
输入格式:"%d"
输出提示信息和格式:
"%d is a leapyear!\n"
"%d is not aleap year!\n"
#include <stdio.h>
main()
{
int year, flag;
printf("Input a year:");
scanf("%d", &year);
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) //1
flag = 1; /* 如果year是闰年,则标志变量flag置1 */
else
flag = 0; /* 否则,标志变量flag置0 */
if (flag==1)
printf("%d is a leap year!\n", year); /* 打印“是闰年”*/
else
printf("%d is not a leap year!\n", year); /* 打印“不是闰年”*/
}