如何在C中以编程方式查找闰年
我使用C制作了一个程序来查找输入的年份是否是闰年。但遗憾的是它运作不佳。它说一年是飞跃,前一年不是飞跃。
#include<stdio.h>#include<conio.h>int yearr(int year);void main(void){ int year; printf("Enter a year:"); scanf("%d",&year); if(!yearr(year)) { printf("It is a leap year."); } else { printf("It is not a leap year"); }getch();}int yearr(int year){ if((year%4==0)&&(year/4!=0)) return 1; else return 0;}
阅读评论后,我编辑了我的编码:
#include<stdio.h>#include<conio.h>int yearr(int year);void main(void){ int year; printf("Enter a year:"); scanf("%d",&year); if(!yearr(year)) { printf("It is a leap year."); } else { printf("It is not a leap year"); }getch();}int yearr(int year){ if((year%4==0) { if(year%400==0) return 1; if(year%100==0) return 0; } else return 0;}
杨__羊羊
相关分类