输入一个年份,判断是否为闰年。
判断闰年的方法是:如果该年能被4整除但不能被100整除;或者能被400整除,就是闰年。
1 #include <stdio.h> 2 3 int main( int argc, char* argv[] ) 4 { 5 6 unsigned long year; 7 8 printf("Input a year:"); 9 scanf("%lu", &year); 10 if((year % 4 == 0 && year % 100 != 0)||(year % 400 == 0)) 11 { 12 printf("Year %lu is a leap year.\n", year); 13 } 14 else 15 { 16 printf("Year %lu is not a leap year.\n", year); 17 } 18 return 0; 19 }
001:判断闰年
时间: 2024-10-12 20:09:20