c语言编程:用数组的知识来设计一个程序 输入一个日期,计算这一天是一年中的第几天
2个回答
展开全部
#include<stdio.h>
main()
{int a[12]={31,28,31,30,31,30,31,31,30,31,30,31},/*平年的*/
b[12]={31,29,31,30,31,30,31,31,30,31,30,31};/*闰年的*/
int year,month,day,sum,n=0;
scanf("%d,%d,%d",&year,&month,&day);
if(year%4==0)
{for(sum=0;n<month;n++)
sum=sum+b[n];
sum=sum+day;}
else
{ for(sum=0;n<month;n++)
sum=sum+a[n];
sum=sum+day;}
printf("%d",sum);
getchar();
}
main()
{int a[12]={31,28,31,30,31,30,31,31,30,31,30,31},/*平年的*/
b[12]={31,29,31,30,31,30,31,31,30,31,30,31};/*闰年的*/
int year,month,day,sum,n=0;
scanf("%d,%d,%d",&year,&month,&day);
if(year%4==0)
{for(sum=0;n<month;n++)
sum=sum+b[n];
sum=sum+day;}
else
{ for(sum=0;n<month;n++)
sum=sum+a[n];
sum=sum+day;}
printf("%d",sum);
getchar();
}
追问
我的意思是日期自己输入。。看是第几天
追答
这里就是输入日期啊,不会看吗?我试过,是可以的。
#include
main()
{int a[12]={31,28,31,30,31,30,31,31,30,31,30,31},/*平年的*/
b[12]={31,29,31,30,31,30,31,31,30,31,30,31};/*闰年的*/
int year,month,day,sum,n=0;
scanf("%d,%d,%d",&year,&month,&day);/*这个就是输入年月日啦*/
if(year%4==0)
{for(sum=0;n<month;n++)
sum=sum+b[n];
sum=sum+day;}
else
{ for(sum=0;n<month;n++)
sum=sum+a[n];
sum=sum+day;}
printf("%d",sum);
getchar();
}
展开全部
#include<stdio.h>
int day_of_year(int (*p)[13],int year,int month,int day)
{
int i,leap;
leap=(year%100 !=0 && year%4 ==0||year%400 ==0);
for(i=1;i<month;i++)
day+=*(*(p+leap)+i);
return day;
}
main()
{
static int day_tab[][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%d\n",day_of_year(day_tab,a,b,c));
}
int day_of_year(int (*p)[13],int year,int month,int day)
{
int i,leap;
leap=(year%100 !=0 && year%4 ==0||year%400 ==0);
for(i=1;i<month;i++)
day+=*(*(p+leap)+i);
return day;
}
main()
{
static int day_tab[][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%d\n",day_of_year(day_tab,a,b,c));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询