Accepted
/in/foo.c: In function 'main': /in/foo.c:48:6: warning: 'num' may be used uninitialized in this function [-Wmaybe-uninitialized] sum=sum+mon_day(y,m);} ~~~^~~~~~~~~~~~~~~~~ /in/foo.c:22:6: note: 'num' was declared here int num; ^~~ /in/foo.c: In function 'mon_day': /in/foo.c:40:9: warning: 'num' may be used uninitialized in this function [-Wmaybe-uninitialized] return num;; ^~~ /in/foo.c: In function 'find': /in/foo.c:48:6: warning: 'num' may be used uninitialized in this function [-Wmaybe-uninitialized] sum=sum+mon_day(y,m);} ~~~^~~~~~~~~~~~~~~~~
代码
#include<stdio.h>
int main()
{
int year,month,day,sum;
scanf("%d,%d,%d",&year,&month,&day);
int p(int year);
int monday(int m);
int find(int y,int m,int d);
sum=find(year,month,day);
printf("%dth\n",sum);
return 0;
}
int p(int year)
{
int leap;
if((year%4==0&&year%100!=0)||(year%400==0))leap=1;
else leap=0;
return leap;
}
int mon_day(int y,int m)
{
int num;
switch(m)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:num=31;break;
case 4:
case 6:
case 9:
case 11:num=30;break;
case 2:{if(y&&(m=2)) num=29;
else num=28;}
break;
}
return num;;
}
int find(int y,int m,int d)
{
int sum=d;
while(m>1)
{
m=m-1;
sum=sum+mon_day(y,m);}
return sum;
}
信息
- 递交者
- 类型
- 递交
- 题目
- 给出年、月、日,计算该日是该年的第几天
- 题目数据
- 下载
- 语言
- C
- 递交时间
- 2018-06-17 19:07:24
- 评测时间
- 2018-06-17 19:07:24
- 评测机
- 分数
- 10
- 总耗时
- 2ms
- 峰值内存
- 256.0 KiB