求高手纠正下我的程序 谢谢 新人
#include <stdio.h>void main()
{
int year,day,leap,days,month;
printf("please input year month and day:");
scanf ("%d %d %d",year,month,day);
if(year%4==0)
{
if (year%100==0)
{
if(year%400==0)
{
leap=1;
}
else
{
leap=0;
}
}
else
{
leap=1;
}
else
{
leap=0;
}
if(leap && month>3)
{
if(month%2==0)
{
days=(30*month)+(month/2)+1;
}
else
{
days=(31*month)-(month/2)+1;
}
}
else
{
if(month%2==0)
{
days=(30*month)+(month/2);
}
else
{
days=(31*month)-(month/2);
}
}
printf("%d",days);
}
上面的程序有错。。。显示说1.说else用错了 2说scanf那有错 3.说最后一个括号}有错
但还是不知道怎样改 求高手帮忙改改谢谢
题目在图片里 #include <stdio.h>
void main()
{
int a={31,28,31,30,31,30,31,31,30,31,30,31};
int year=0;
int mon=0;
int day=0;
int sum=0;
int i=0;
printf("请输入日期:格式为1900,8,15,……\n");
scanf("%d,%d,%d\n",&year,&mon,&day);
switch (mon)
{
case 1:
{
printf("%d年%d月%d日是%d年的第%d天!\n",year,mon,day,year,day);
break;
}
case 2:
{
sum=31+day;
printf("%d年%d月%d日是%d年的第%d天!\n",year,mon,day,year,sum);
break;
}
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
{
for (i=1;i<mon;i++)//此处i!=mon,相等时取得是该月的总天数
{
sum+=a;
}
sum+=day;
if (year%4==0&&year%100>0||year%400==0)
{
printf("%d年%d月%d日是%d年的第%d天!\n",year,mon,day,year,sum+1);
}
else
{
printf("%d年%d月%d日是%d年的第%d天!\n",year,mon,day,year,sum);
}
break;
}
}
兄弟,这是我自己写的代码,你可以参考下!
我的思路是:
1.如果输入的是一月份,直接输出day
2.如果输入的是二月份,直接输出31+day
3.如果输入的是三到十二月份,mon-1个月相加再加上day。再判断是否是闰年,是的话结果再加1天。
#include <stdio.h>
void main()
{
int year,day,leap,days,month;
printf("please input year month and day:");
scanf ("%d %d %d",year,month,day);此处的%d改为%d,%d,%d,&year,&month,&day
if(year%4==0)
{
if (year%100==0)
{
if(year%400==0)
{
leap=1;
}
else
{
leap=0;
}
}
else
{
leap=1;
}
此处少了一个}
else
{
leap=0;
}
if(leap && month>3)
{
if(month%2==0)
{
days=(30*month)+(month/2)+1;
}
else
{
days=(31*month)-(month/2)+1;
}
}
else
{
if(month%2==0)
{
days=(30*month)+(month/2);
}
else
{
days=(31*month)-(month/2);
}
}
printf("%d",days);
} 不错网上还是有高人在啊 薄年再无木小白 发表于 2013-12-8 10:33 static/image/common/back.gif
不错网上还是有高人在啊
编程是个细心的活,必须严谨,要形成自己的编程风格!:lol:
页:
[1]