C++程序:给出年月日,计算该日是该年的第几天
答案:1 悬赏:30 手机版
解决时间 2021-03-07 23:31
- 提问者网友:椧運幽默
- 2021-03-07 20:04
C++程序:给出年月日,计算该日是该年的第几天
最佳答案
- 五星知识达人网友:青灯有味
- 2021-03-07 20:50
# include
# include
int sum_day(int month, int day);
int leap(int year);
void main()
{
int year, month, day;
int days;
printf("请输入日期(年,月,日):");
scanf("%d, %d, %d", &year, &month, &day);
printf("%d年%d月%d日", year, month, day);
days = sum_day(month, day);
if(leap(year) && month>=3)
days = days + 1;
printf("是该年的第%d天.\n", days);
getch();
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i
day = day + day_tab[i];
return day;
}
int leap(int year)
{
int leap;
leap = (year%4==0&&year%100!=0)||(year%400==0);
return leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
# include
int sum_day(int month, int day);
int leap(int year);
void main()
{
int year, month, day;
int days;
printf("请输入日期(年,月,日):");
scanf("%d, %d, %d", &year, &month, &day);
printf("%d年%d月%d日", year, month, day);
days = sum_day(month, day);
if(leap(year) && month>=3)
days = days + 1;
printf("是该年的第%d天.\n", days);
getch();
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i
day = day + day_tab[i];
return day;
}
int leap(int year)
{
int leap;
leap = (year%4==0&&year%100!=0)||(year%400==0);
return leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯