多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# C 程序:检查闰年 > 原文: [https://beginnersbook.com/2017/09/c-program-to-check-leap-year/](https://beginnersbook.com/2017/09/c-program-to-check-leap-year/) 该程序检查输入年份是否为闰年。 ## 示例:检查闰年的程序 您可以使用以下数学逻辑检查一年是否是闰年: **闰年:** 如果一年可以被 4, 100 和 400 整除,则它是闰年。 如果一年可以被 4 整除但不能被 100 整除那么它就是闰年 **不是闰年:** 如果一年不能被 4 整除那么它不是闰年 如果一年可被 4 和 100 整除但不能被 400 整除那么它就不是闰年 让我们在 C 程序中编写这个逻辑。要了解该程序,您应该具有以下 [C 编程](https://beginnersbook.com/2014/01/c-tutorial-for-beginners-with-examples/)主题的知识: * [C 编程`if..else`,嵌套`if..else`](https://beginnersbook.com/2014/01/c-if-else-statement-example/) ```c #include <stdio.h> int main() { int y; printf("Enter year: "); scanf("%d",&y); if(y % 4 == 0) { //Nested if else if( y % 100 == 0) { if ( y % 400 == 0) printf("%d is a Leap Year", y); else printf("%d is not a Leap Year", y); } else printf("%d is a Leap Year", y ); } else printf("%d is not a Leap Year", y); return 0; } ``` 输出: ```c Enter year: 1991 1991 is not a Leap Year ``` 看看这些相关的 C 程序: 1. [C 程序:检查字母是元音还是辅音](https://beginnersbook.com/2017/09/c-program-to-check-whether-an-alphabet-is-vowel-or-consonant/) 2. [C 程序:检查数字是否是回文](https://beginnersbook.com/2015/02/c-program-to-check-if-a-number-is-palindrome-or-not/) 3. [C 程序:检查阿姆斯壮编号](https://beginnersbook.com/2014/06/c-program-to-check-armstrong-number/) 4. [C 程序:检查数字是偶数还是奇数](https://beginnersbook.com/2015/02/c-program-to-check-if-number-is-even-or-odd/) 5. [C 程序:检查数字是正数还是负数](https://beginnersbook.com/2015/02/c-program-to-check-whether-the-given-integer-is-positive-or-negative/)