写一个C语言代码 输入年月日确实该日是该年的哪一天
- 提问者网友:暗中人
- 2021-05-02 08:19
- 五星知识达人网友:举杯邀酒敬孤独
- 2021-05-02 09:43
#include <stdio.h>
void main()
{
int year,month,day,sum=0,is=0,t;
scanf("%d%d%d",&year,&month,&day);
switch(month) {
case 12:
sum+=day; is=1;
case 11:
if(is) sum+=30;
else sum+=day;
is=1;
case 10:
if(is) sum+=31;
else sum+=day;
is=1;
case 9:
if(is) sum+=30;
else sum+=day;
is=1;
case 8:
if(is) sum+=31;
else sum+=day;
is=1;
case 7:
if(is) sum+=31;
else sum+=day;
is=1;
case 6:
if(is) sum+=30;
else sum+=day;
is=1;
case 5:
if(is) sum+=31;
else sum+=day;
is=1;
case 4:
if(is) sum+=30;
else sum+=day;
is=1;
case 3:
if(is) sum+=31;
else sum+=day;
is=1;
case 2:
if(is)
{
if(year%4==0 && (year%100!=0||year%400==0)) sum+=29;
else sum+=28;
}
else sum+=day;
is=1;
case 1:
if(is) sum+=31;
else sum+=day;
}
printf("%d-%d-%d is %d\n",year,month,day,sum);
}
- 1楼网友:千杯敬自由
- 2021-05-02 12:31
#include <stdio.h> int countDays(int year,int month,int day) { int days=0; int i; for(i=1;i<month;i++){ if(i==1||i==3||i==5||i==7||i==8||i==10||i==31) days+=31; else if(i==2){ if(year%4==0||year%400==0||year%100==0) days+=29; else days+=28; } else days+=30; } return (days+day); } int main(int argc, char** argv) { int year,month,day,date; printf("please input the date like this:year,month,day:"); scanf("%d,%d,%d",&year,&month,&day); date=countDays(year,month,day); printf("the %d-%d-%d is the %d 's %d days\n",year,month,day,year,date); return 0; }
- 2楼网友:往事埋风中
- 2021-05-02 11:48
强烈BS楼上!!!!!!
#include<stdio.h> void main () { int year,manth,day,n; while(scanf("%d/%d/%d",&year,&manth,&day)!=EOF) { n=0; if(year%4==0&&year%100!=0||year%400==0) { if(manth==1) n=day; else if(manth==2) n=31+day; else if(manth<=3) n=30*(manth-1)+day; else if(manth<=5) n=30*(manth-1)+day+1; else if(manth<=7) n=30*(manth-1)+day+2; else if(manth<=8) n=30*(manth-1)+day+3; else if(manth<=10) n=30*(manth-1)+day+4; else n=30*(manth-1)+day+5; } else { if(manth==1) n=day; else if(manth==2) n=31+day; else if(manth<=3) n=30*(manth-1)+day-1; else if(manth<=5) n=30*(manth-1)+day; else if(manth<=7) n=30*(manth-1)+day+1; else if(manth<=8) n=30*(manth-1)+day+2; else if(manth<=10) n=30*(manth-1)+day+3; else n=30*(manth-1)+day+4; } printf("%d\n",n); } }
还要注释么?
- 3楼网友:往事隔山水
- 2021-05-02 10:47
我知道
printf(“写一个C语言代码 输入年月日确实该日是该年的哪一天”)