关于C语言的问题。设计一个程序,根据用户的选择,将1、日期转换为天数2、将天数转换为日期。
答案:4 悬赏:0 手机版
解决时间 2021-03-17 07:11
- 提问者网友:嘚啵嘚啵
- 2021-03-16 15:57
关于C语言的问题。设计一个程序,根据用户的选择,将1、日期转换为天数2、将天数转换为日期。
最佳答案
- 五星知识达人网友:逃夭
- 2021-03-16 17:26
是当年的吧,要是跨年,计算就不是这水平的了
~
~
~
~
~
~
全部回答
- 1楼网友:荒野風
- 2021-03-16 18:57
没明白你说的天数是什么意思?
- 2楼网友:woshuo
- 2021-03-16 18:49
代码存在一些问题:
#include#define MAXNUM2 14
int main()
{
int a,b,c,Y,M,D,Days;
int Days_[MAXNUM1]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int Date[MAXNUM2]={0,1,2,3,4,5,6,7,8,9,10,11,12};
printf("Plese choose what you want to do. 1.Date change Days 2.Days change Date ");
scanf("%d",&a);
if(a==1)
{ Days = 0;
printf("Plese enter a date(YMD). ");
scanf("%d %d %d",&Y,&M,&D);
if(Y%4==0&&Y%100!=0||Y%400==0)//这里改下
{
for(b=1;b < M;b++)
if(b==2)//闰年二月加一天
{
Days+=Days_[b]+1; }
else
{
Days+=Days_[b];
}
}else
{
for(b=1;b < M;b++)
{
Days+=Days_[b];
}
}
Days += D;
printf("The date which you enter is the %d days. ",Days);
}else //a==2
{
printf("Plese enter a days.");
scanf("%d",&Days);
for(b=1;b < 13;b++)//未考虑年份的问题
{
if(Days <= Days_[b]) break;
Days -= Days_[b];
}
printf("The day which you enter is the %d\%d days. ",b,Days);
}
}
上面是简单的实现,希望有帮助
追问多谢啦。我之前已经采纳了一个,不过你的也是很好的。如果能采纳两个的话就好了。我就连你的也采纳。- 3楼网友:未来江山和你
- 2021-03-16 18:16
// xx.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
int main()
{
#define MAXNUM1 14
#define MAXNUM2 14
int a,b,Y,M,D,Days;
int Days_[MAXNUM1]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int Date[MAXNUM2]={0,1,2,3,4,5,6,7,8,9,10,11,12};
printf("Plese choose what you want to do. 1.Date change Days 2.Days change Date ");
scanf("%d",&a);
if(a==1)
{
printf("Plese enter a date(Y\M\D). ");
scanf("%d %d %d",&Y,&M,&D);
for(Days=0,b=1;b Days += Days_[b];
Days += D;
if(Y%4==0 && (Y%100!=0||Y%400==0))
++Days;
printf("The date which you enter is the %d days. ",Days);
}
else
{
printf("Plese enter a days.");
scanf("%d",&Days);
}
return 0;
}
//
#include "stdafx.h"
#include
int main()
{
#define MAXNUM1 14
#define MAXNUM2 14
int a,b,Y,M,D,Days;
int Days_[MAXNUM1]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int Date[MAXNUM2]={0,1,2,3,4,5,6,7,8,9,10,11,12};
printf("Plese choose what you want to do. 1.Date change Days 2.Days change Date ");
scanf("%d",&a);
if(a==1)
{
printf("Plese enter a date(Y\M\D). ");
scanf("%d %d %d",&Y,&M,&D);
for(Days=0,b=1;b
Days += D;
if(Y%4==0 && (Y%100!=0||Y%400==0))
++Days;
printf("The date which you enter is the %d days. ",Days);
}
else
{
printf("Plese enter a days.");
scanf("%d",&Days);
}
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯