想了两天啦 还是不会啊
给出年月日,计算该日是该年的第几天
看看是不是闰年就行了 然后把1 3 5 7 8 10 12这么月份设计为31天 由于二月不同
打两个表就行了

程序代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 20
int count_days(struct input n);
int judge(char month[],char str1[],char str2[],char str3[]);
struct input
{
int year;
char month[SIZE];
int day;
};
void main()
{
struct input n;
int num;
printf("Input year,please!\n");
scanf("%d",&n.year);
printf("Input month,please!\n");
fflush(stdin);
gets(n.month);
printf("Input day,please!\n");
scanf("%d",&n.day);
num=count_days(n);
printf("%d\n",num);
system("pause");
}
int count_days(struct input n)
{
int all_year1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int all_year2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int *p,i;
int number=0,mon,numbers;
if(n.year%4==0&&n.year%100!=0||n.year%400==0)
p=all_year2;
else
p=all_year1;
if(judge(n.month,"1","一月","Jan"))
mon=1;
else if(judge(n.month,"2","二月","Feb"))
mon=2;
else if(judge(n.month,"3","三月","Mar"))
mon=3;
else if(judge(n.month,"4","四月","Apr"))
mon=4;
if(judge(n.month,"5","五月","May"))
mon=5;
if(judge(n.month,"6","六月","Jun"))
mon=6;
if(judge(n.month,"7","七月","Jul"))
mon=7;
if(judge(n.month,"8","八月","Aug"))
mon=8;
if(judge(n.month,"9","九月","Sep"))
mon=9;
if(judge(n.month,"10","十月","Oct"))
mon=10;
if(judge(n.month,"11","十一月","Nov"))
mon=11;
if(judge(n.month,"12","十二月","Dec"))
mon=12;
for(i=0;i<mon-1;i++)
number+=p[i];
numbers=number+n.day;
return numbers;
}
int judge(char month[],char str1[],char str2[],char str3[])
{
if(strcmp(month,str1)==0||strcmp(month,str2)==0||strcmp(month,str3)==0)
return 1;
else
return 0;
}
收!
程序代码:/*
题目:输入某年某月某日,判断这一天是这一年的第几天?
程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。
*/
#include<stdio.h>
#include<windows.h>
int main(void)
{
int a,i=300,d,m,y,j,days;
do{
printf("请输入年份:");
scanf("%d",&y);
do
{
printf("请输入月份:");
scanf("%d",&m);
if(m>12||m==0)
{
printf("不好意思!您的月份输错了,一年只有12个月哟,亲!\n");
Beep(1000,1050);
}
}
while(m>12||m==0);
do
{
printf("请输入日期:");
scanf("%d",&d);
if(((y%4==0||(y%4==0&&y%100!=0))&&(m==2))&&(d>29))
{
printf("您输入的日期有误!\n");
Beep(1000,1000);
j=1;
}
else if((!(y%4==0||(y%4==0&&y%100!=0)))&&(m==2)&&(d>28))
{
printf("您输入的日期有误!\n");
Beep(1000,1000);
j=1;
}
else if(((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&(d>31)))
{
printf("您输入的日期有误!\n");
Beep(1000,1000);
j=1;
}
else if((m==2||m==4||m==6||m==9||m==11)&&(d>30))
{
printf("您输入的日期有误!\n");
Beep(1000,1000);
j=1;
}
else
j=0;
}
while(1==j);
{
switch(m)
{
case 1:
a=0;
break;
case 2:
a=31;
break;
case 3:
a=59;
break;
case 4:
a=90;
break;
case 5:
a=120;
break;
case 6:
a=151;
break;
case 7:
a=181;
case 8:
a=212;
break;
case 9:
a=243;
break;
case 10:
a=273;
break;
case 11:
a=304;
break;
case 12:
a=334;
break;
default:
break;
}
if(y%4==0||(y%4==0&&y%100!=0))
{
if(m>2)
{
days=a+d+1;
printf("\n %d 年!本年是闰年,共366天!您输入的日期是本年的第 %d 天!\n",y,days);
}
else
{
days=a+d;
printf("\n %d 年!本年是闰年,共366天!您输入的日期是本年的第 %d 天!\n",y,days);
}
}
else
{
days=a+d;
printf("\n %d 年!本年是平年,共365天!您输入的日期是本年的第 %d 天!\n",y,days);
}
}
printf("是否继续使用呢?继续请按1(否则按其它数字):");
scanf("%d",&j);
}
while(1==j);
}
噢,我还加了些没用的报警声音,本来就是练习的嘛!