马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 LH魔王 于 2020-7-1 17:50 编辑 /*输入某年、某月、某日,判断这一天是这一年的第几天*/
#include<stdio.h>
int judgement(int x)
{
if((x%4 == 0) && (x%100 != 0))
{
return 1;
}
else if((x%400==0)&&(x%100==0))
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int year,month,day,judge,result;
printf("请输入年:");
scanf("%d",&year);
printf("请输入月:");
scanf("%d",&month);
printf("请输入日:");
scanf("%d",&day);
switch(month)
{
case 1:result=day;break;
case 2:result=31+day;break;
case 3:result=31+28+day;break;
case 4:result=31+28+31+day;break;
case 5:result=31+28+31+30+day;break;
case 6:result=31+28+31+30+31+day;break;
case 7:result=31+28+31+30+31+30+day;break;
case 8:result=31+28+31+30+31+30+31+day;break;
case 9:result=31+28+31+30+31+30+31+31+day;break;
case 10:result=31+28+31+30+31+30+31+31+30+day;break;
case 11:result=31+28+31+30+31+30+31+31+30+31+day;break;
case 12:result=31+28+31+30+31+30+31+31+30+31+30+day;break;
}
judge=judgement(year);
if (judge==1)
{
if (month>2)
result=result+1;
}
printf("%d年%d月%d日是%d年的第%d天",year,month,day,year,result);
}
|