方法一
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int year = 0;
while(1)
{
printf("请输入一个年份:>");
scanf("%d", &year);
if (year % 100 == 0 && year % 400 == 0 && year % 4 == 0)
printf("%d是闰年\n",year);
else
printf("%d不是闰年\n",year);
}return 0;
}
方法二
#define _CRT_SECURE_NO_WARNINGS 1标签:年份,闰年,int,max,year,是不是,&&,printf From: https://blog.51cto.com/EddieLai/6111338
#include <stdio.h>
int main()
{
int year = 0;
int max = 0;
while (1)
{
printf("请输入一个年份:>");
scanf("%d", &year);
max = (year % 400 == 0 && year % 4 == 0 && year % 100 == 0)? 1: 0;//三目运算符
if (max == 1)
printf("%d是闰年\n", year);
else
printf("%d不是闰年\n", year);
}
return 0;
}