C语言:定义2个函数:leap()判断闰年,day()计算某日期在当年的天数。
发布网友
发布时间:2024-10-03 11:10
我来回答
共2个回答
热心网友
时间:2024-10-24 23:28
#include<stdio.h>
#include<stdlib.h>
int leap(void)
{
int year;
bool r;
printf("Enter a year: ");
scanf("%d", &year);
printf("\n");
if(year%4==0 && year%100!=0||year%400==0 )
r = true ;
else
r = false ;
if( r )
printf("%d年是闰年\n", year );
else
printf("%d年是平年\n",year);
system("pause");
return 0;
}
int day()
{
printf("Enter a date:");
int month,date;int time;
scanf("%d%d",&month,&date);
switch(month)
{
case 1:time=date;break;
case 2:time=31+date;break;
case 3:time=59+date;break;
case 4:time=90+date;break;
case 5:time=120+date;break;
case 6:time=151+date;break;
case 7:time=181+date;break;
case 8:time=212+date;break;
case 9:time=243+date;break;
case 10:time=273+date;break;
case 11:time=304+date;break;
case 12:time=334+date;break;
}
printf("第%d天",time);
return 0;
}
int main(void)
{
leap();
day()
return 0}
热心网友
时间:2024-10-24 23:28
#include<stdio.h>
void main()
{
int y,m,d,sum,i;
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
while((scanf("%d/%d/%d",&y,&m,&d))!=EOF)
{
sum=d;
if(y%4==0&&y%100!=0||y%400==0)
month[2]=29;
else
month[2]=28;
for(i=1;i<m;i++)
sum+=month[i];
printf("%d\n",sum);
}
}
具体思路就是这样子追问能把运行的图截给我看下吗?
追答