在C语言中,可以使用以下方法判断闰年:1. 若该年份能被4整除但不能被100整除,则为闰年;2. 若该年份能被400整除,则为闰年;
在C语言中,可以使用以下方法判断闰年:
1. 若该年份能被4整除但不能被100整除,则为闰年;
2. 若该年份能被400整除,则为闰年;
3. 其他情况下均为平年。
下面是一个示例代码:
```c
#include
int isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return 1; // 是闰年
} else {
return 0; // 不是闰年
}
}
int main() {
int year;
printf("请输入年份:");
scanf("%d", &year);
if (isLeapYear(year)) {
printf("%d年是闰年\n", year);
} else {
printf("%d年不是闰年\n", year);
}
return 0;
}
```
运行程序后,根据输入的年份会判断其是否为闰年,并输出相应的结果。
--结束END--
本文标题: c语言中怎么判断闰年
本文链接: https://www.lsjlt.com/news/402989.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0