求助:一道初级的C语言程序设计的题目,开头是#include的那种……

来源:百度知道 编辑:UC知道 时间:2024/05/23 16:52:18
用循环结构程序设计下题:输入月日,要求输出是这年的第几天?还要考虑闰年这种特殊情况……谢谢大虾……

#include<stdio.h>
void main()
{
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int b[12]={31,29,31,30,31,30,31,31,30,31,30,31};
printf("input the year and month and day:\n");
int year,month,day;
scanf("%d%d%d",&year,&month,&day);
int sum=0;
if(year%400==0)
{
for(int i=0;i<12;i++)
{
if(month>=i);
sum+=b[i];
}
sum+=day;
printf("the day is %d days in this year.\n",sum);
}
else{
for(int i=0;i<12;i++)
{
if(month>=i);
sum+=a[i];
}
sum+=day;
printf("the day is %d days in this year.\n",sum);
}
}

#include<stdio.h>
main()
{
int day,month,year,sum,leap;
printf("\nplease input year,month,day\n");
scanf("%d,%d,%d",&year,&month,&day);
switch(month)
{
case 1: