我刚刚开始介绍c编程课程-我正在尝试编写一个程序,以打印输入的开始和结束之间的所有the年。
#include <stdio.h>
int main (void) {
int start, finish, leap;
printf("Enter start year: ");
scanf("%d", &start);
printf("Enter finish year: ");
scanf("%d", &finish);
while (start <= finish) {
if ((start%400 == 0) || (start%4 == 0))
else if (start%100 != 0)
}
printf("%d\n", start);
start = start + 1
return 0;
}
我不断收到“期望的表达式”错误,它指向else if语句的开头。分阶段工作,并且if语句可以打印出整整为400或4的年份。
我正在尝试排除现在可以被100整除的数字...关于出了什么问题的任何想法?
最佳答案
您的问题比您想象的要简单。看下面的代码:
if ((start%400 == 0) || (start%4 == 0))
else if (year%100 != 0)
您有一个if语句,其后没有任何语句。
if ((start%400 == 0) || (start%4 == 0)) {}
else if (year%100 != 0) {}
这样可以解决该错误,但是我确定您想在这些代码块中做点什么!
关于c - 否则,如果在确定C中的If年时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36202511/