标题:计算出生至今共度过多少天。
取消只看楼主
xwjzm2002
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-5
 问题点数:0 回复次数:0 
计算出生至今共度过多少天。

#include "stdio.h"
main()
{
int year,month,day,nyear,nmonth,nday;
int days,dayn1=0,dayn2,iyear,dayyear;
int i;
int monthtable[]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("birthday=");
scanf("d% d% d%",&year,&month,&day);
if(year<=0||month<1||month>12||day<=0||day>31)
printf("data error\n");
printf("year,month,day is");
scanf("d% d% d%",&nyear,&nmonth,&nday);
if(nyear<=0||nmonth<1||nmonth>12||nday<=0||nday>31)
printf("data error");
iyear=year;
for(;iyear<=nyear-1;iyear++)
{if((iyear%4==0&&iyear%100!=0)||iyear%400==0)
dayyear=366;
else
dayyear=365;
dayn1=dayn1+dayyear;
}
if((nyear%4==0&&nyear%100!=0)||nyear%400==0)
monthtable[1]=29;

dayn2=nday;
for(i=1;i<nmonth;i++)
{dayn2=dayn2+monthtable[i-1];
days=dayn1+dayn2;
}
printf("days isd%",days);
getch();
}
上面是小妹写的程序,但是在WIN-TC上能编译,但是只要运行第一个输入后,不经过运算,原样输出printf后的语句(不计算),不知怎搞的,望指教,么么。。

搜索更多相关主题的帖子: month int day 
2007-08-09 16:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-161529-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.730116 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved