我需要在代码中使用一个if语句,而不是使用3,是否有人知道我该怎么做? 我的代码:
#include < stdio.h >
int main() {
int year;
printf("Enter a year: ");
scanf("%d", & year);
if (year % 4 == 0) {
if (year % 100 == 0) {
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;
}
答案 0 :(得分:-2)
是的,我们可以使用一个if语句来做到这一点。
if((year%4==0 && year%100!=0) || year%400==0)
{
printf("%d is a leap year.", year);
}
else
{
printf("%d is not a leap year.", year);
}