这行代码为什么不能正常运行?
#include <stdio.h>int main()
{
int year, result;
printf("请输入年份:");
scanf("%d", year);
result = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
printf("%d\n", year);
printf("%d\n", result);
if (result = 0)
{
printf("%d不是闰年!\n", year);
return 0;
}
else
{
printf("%d是闰年!\n", year);
return 0;
}
}
运行结果如图
#include <stdio.h>
int main()
{
int year, result;
printf("请输入年份:");
scanf("%d", &year);// 这里要传入地址
result = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
if (result == 0)// 判断是==,=是赋值
{
printf("%d不是闰年!\n", year);
}
else
{
printf("%d是闰年!\n", year);
}
return 0;
} 临时号 发表于 2022-8-15 13:13
谢谢!!!
页:
[1]