如何在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;}
3 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
int isLeapYear(int year){ return (year % 400 == 0) || ( ( year % 100 != 0) && (year % 4 == 0 ));}
- 3 回答
- 0 关注
- 675 浏览
添加回答
举报
0/150
提交
取消