#include <stdio.h>
int main()
{
int year=0;
int mouth=0;
int day=0;
int sun=0;
printf("请输入年月日");
scanf("%d %d %d",&year,&mouth,&day);
sun=(mouth-1)*30+day;
if((year%4==0 && year%100!=0)|| year%400==0) {
if(mouth==1)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==2)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==3)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==4)
printf("%d月%d日是%d年中的%d天",mouth,day,year,+1);
else if(mouth==5)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==6)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+2);
else if(mouth==7)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+2);
else if(mouth==8)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+3);
else if(mouth==9)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
else if(mouth==10)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
else if(mouth==11)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+5);
else if(mouth==12)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+5);
}
else {
if(mouth==1)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==2)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==3)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun-1);
else if(mouth==4)
printf("%d月%d日是%d年中的%d天",mouth,day,year);
else if(mouth==5)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun-1);
else if(mouth==6)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+1);
else if(mouth==7)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+1);
else if(mouth==8)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+2);
else if(mouth==9)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+3);
else if(mouth==10)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+3);
else if(mouth==11)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
else if(mouth==12)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
}
return 0;
int main()
{
int year=0;
int mouth=0;
int day=0;
int sun=0;
printf("请输入年月日");
scanf("%d %d %d",&year,&mouth,&day);
sun=(mouth-1)*30+day;
if((year%4==0 && year%100!=0)|| year%400==0) {
if(mouth==1)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==2)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==3)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==4)
printf("%d月%d日是%d年中的%d天",mouth,day,year,+1);
else if(mouth==5)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==6)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+2);
else if(mouth==7)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+2);
else if(mouth==8)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+3);
else if(mouth==9)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
else if(mouth==10)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
else if(mouth==11)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+5);
else if(mouth==12)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+5);
}
else {
if(mouth==1)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==2)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun);
else if(mouth==3)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun-1);
else if(mouth==4)
printf("%d月%d日是%d年中的%d天",mouth,day,year);
else if(mouth==5)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun-1);
else if(mouth==6)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+1);
else if(mouth==7)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+1);
else if(mouth==8)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+2);
else if(mouth==9)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+3);
else if(mouth==10)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+3);
else if(mouth==11)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
else if(mouth==12)
printf("%d月%d日是%d年中的%d天",mouth,day,year,sun+4);
}
return 0;
}
一开始有两个错误
1.
判断的时候写成了if(mouth=x),所以导致输出的结果跟出入的不一样 应改为if(mouth==x)
2.
虽然if后面或者else if 后面都是单个语句 不用加括号,但是与第一个if对应的else后面还有一个if,不加括号的情况下系统理解为,与第一个if对应的else与这个else后面的if 组成else if
所以与第一个if对应的else后面要加大括号