判断闰年
作者:互联网
1、判断闰年
1 #include<stdio.h> 2 int main() 3 { 4 int year,leap; 5 printf("please enter year: "); 6 scanf("%d",&year); 7 if(year%4==0) 8 { 9 if(year%100==0) 10 {if(year%400==0) 11 leap==1; 12 else 13 leap=0; 14 } 15 elae 16 leap=1; 17 } 18 else 19 leap=0; 20 if(leap) 21 printf("%d is ",year); 22 elae 23 printf("%d is not ",year); 24 printf("a leap year.\n"); 25 return 0; 26 }
法2:
1 #include<stdio.h> 2 int main() 3 { 4 int year,leap; 5 printf("please enter year: "); 6 scanf("%d",&year); 7 if(year%4==0&&year%100!=0||(year%400==0)) 8 leap=1; 9 else 10 leap=0; 11 if(leap) 12 printf("%d is ",year); 13 else 14 printf("%d is not ",year); 15 printf("a leap year.\n"); 16 return 0; 17 }
法3
1 #include<stdio.h> 2 int main() 3 { 4 int year,leap; 5 printf("please enter year: "); 6 scanf("%d",&year); 7 if(year%4!=0) 8 leap=0; 9 else 10 if(year%100!=0) 11 leap=1; 12 else 13 if(year%400!=0) 14 leap=0; 15 else 16 leap=1; 17 18 if(leap) 19 printf("%d is ",year); 20 else 21 printf("%d is not ",year); 22 printf("a leap year.\n"); 23 return 0; 24 }
标签:判断,闰年,int,year,else,leap,printf,year% 来源: https://www.cnblogs.com/1998wdq/p/11209592.html