#include <stdio.h>
int year(int x,int y,int z){
int m;
int d = 0,i,sum=0;
int a[]= {31,28,31,30,31,30,31,31,30,31,30,31};
if((x%4==0&&x%100!=0)||x%400==0){
m =1;
a[1] = 29;
for(i = (y-2); 0<=i;i--){
d +=a[i];
}
}else{
m =0;
for(i = (y-2); 0<=i;i--){
d +=a[i];
}
}
sum= d+z;
printf("%d年%d月%d日,是%d的第%d天 \n",x,y,z,x,sum);
printf("%d \n",m);
return 0;
}
int main()
{
int x, y, z;
printf("请输入年:");scanf("%d",&x);
printf("请输入月:");scanf("%d",&y);
while(y>12||y<=0){
printf("您输入的月份无效,请重新输入:");
scanf("%d",&y);
}
printf("请输入日:");scanf("%d",&z);
while(z>31||z<=0){
printf("您输入的日期无效,请重新输入:");
scanf("%d",&z);
}
year(x,y,z);
return 0;
}
输入年月日求是该年的第几天?主函数调用闰年函数,若是闰年返回1否则返回0
最新推荐文章于 2024-11-12 12:29:51 发布