c语言计算天数的函数,C语言计算出生日到计算日的总天数

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

bbfatcat

2014.06.28

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:50%    等级:7

已帮助:59人

fun(int a)

{

if((a%4==0&&a%100!=0)||a%400==0) return (1);

else return (0);

}/*用来判断是否为闰年*/

fun1(int year,int month,int day)

{ int c[12],i,j,k=0;

int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};

int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};

j=fun(year);

if(j==1) for(i=0;i<12;i++) c[i]=a[i];

if(j==0) for(i=0;i<12;i++) c[i]=b[i];

for(i=0;i

k=k+day;

return k;

}/*用来求你说的day1,day2*/

main()

{

int month=0,year=0,day=0,bmonth=0,byear=0,bday=0,sum=0,i;

while(byear<1||byear>32000)

{ printf("please input the birthyear:\n");

scanf("%d",&byear); }

while(bmonth<1||bmonth>12)

{ printf("please input the birthmonth:\n");

scanf("%d",&bmonth); }

while(bday<1||bday>31)

{ printf("please input the birthday:\n");

scanf("%d",&bday);}

printf("your birthday is:%d %d %d\n",byear,bmonth,bday);

while(year<1||year>32000)

{ printf("please input the coutyear:\n");

scanf("%d",&year); }

while(month<1||month>12)

{ printf("please input the coutmonth:\n");

scanf("%d",&month); }

while(day<1||day>31)

{ printf("please input the coutday:\n");

scanf("%d",&day);}

printf("cout day is:%d %d %d\n",year,month,day);

printf("day1=%d\nday2=%d\n",fun1(byear,bmonth,bday),fun1(year,month,day));

for(i=byear;i

sum+=365+(fun(i));

printf("anser:%d",fun1(year,month,day)-fun1(byear,bmonth,bday)+sum);

getch();

}

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值