c语言编程题目
发布网友
发布时间:2022-03-08 15:40
我来回答
共2个回答
热心网友
时间:2022-03-08 17:09
struct date{
int year;
int month;
int day;
}date;
char monthday[]={31,28,31,30,31,30,31,31,30,31,30,31};
int Count()
{
int i=0;
int d;
int yy;
d=0;
yy=date.year;
for(i=1;i<date.month;i++)
d+=monthday[i-1];
d+=date.day;
if(((yy%4==0&&yy%100!=0)||yy%400==0)&&date.month>2) d++;
return d;
}
int main()
{
int N;
printf("Enter the date(yy-mm-dd):");
scanf("%d-%d-%d",&date.year,&date.month,&date.day);
printf("%d",Count());
getchar();
getchar();
getchar();
}
热心网友
时间:2022-03-08 18:27
#include<stdio.h>
void main()
{
int nian,yue,ri,leap,sum;
printf("\n 请输入年月日: \n");
scanf("%d%d%d",&nian,&yue,&ri);
switch(yue)
{
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("\n 数据错误 \n");
}
sum=sum+ri;
if((nian%400==0) ||(nian%4==0 && nian%100!=0 ))
leap=1;
else
leap=0;
if(leap==1 && nian>3)
sum++;
printf("\n 这一天是这一年的第 %d 天 \n",sum);
}