小白求助
输入年月日,求这一天是这一年的第几天,帮忙看下,代码哪里出了问题,在vc上面输了年月日,按回车没反应,运行不了#include <stdio.h>
void main ()
{
int year, month , day , sum ,leap;
printf("please input year ,month , day \n");
scanf("%d%d%d",year,month,day);
switch(month)
{
case 1:sum=0;break;
case 2: sum=31;break;
case 3: sum =59;break;
case 4: sum =90;break;
case 5 : sum =120;break;
case 6:sum =151;break;
case 7: sum =181;break;
case 8: sum =212;break;
case 9: sum =243;break;
case 10: sum =273;break;
case 11: sum=304;break;
case 12: sum =334;break;
default:printf("data error");break;
}
sum =sum+day;
if((year%400==0)||(year%4==0&&year%100!=0))
leap=1;
else
leap=0;
if (leap==1&&month>2)
sum++;
printf("%d",sum);
}
scanf语句没有取址符哦 #include <stdio.h>
void main ()
{
int year, month, day, sum,leap;
printf("please input year ,month , day \n");
scanf("%d%d%d",&year,&month,&day);
switch(month)
{
case 1:
sum=0;break;
case 2:
sum=31;break;
case 3:
sum =59;break;
case 4:
sum =90;break;
case 5 :
sum =120;break;
case 6:
sum =151;break;
case 7:
sum =181;break;
case 8:
sum =212;break;
case 9:
sum =243;break;
case 10:
sum =273;break;
case 11:
sum=304;break;
case 12:
sum =334;break;
default:
printf("data error");break;
}
if((year%4==0&&year%100!=0)||year%400==0)
{
leap=1;
}
else
{
leap=0;
}
if(month>2)//判断是否为闰年过后,判断是否超过2月
{
sum=sum+day+leap;
}
else sum=sum+day;
printf("\n%d月%d日是%d年的第%d天\n",month,day,year,sum);
}
龙龙龙龙龙龙 发表于 2020-2-14 22:54
还有个想请问下,case后面的数字不用加‘’吗,比如case‘ 1 ’这样子,但是看了书上其他例题case‘A’这种是加了分号的 张世来4610484 发表于 2020-2-15 13:30
还有个想请问下,case后面的数字不用加‘’吗,比如case‘ 1 ’这样子,但是看了书上其他例题case‘A ...
' '里是字符表达样式,'1'是1这个字符,ASCII码是49
页:
[1]