代码存在一些问题:
#include<stdioh#define MAXNUM1 14
#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\n1Date change Days\n2Days change Date\n");
scanf("%d",&a);
if(a==1)
{ Days = 0;
printf("Plese enter a date(Y\M\D)\n");
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\n",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\n",b,Days);
}
}
上面是简单的实现,希望有帮助
#include <iostreamh>
class Date
{
private:
int year,month,day;
public:
Date(int y, int m, int d)
{
year=y;
month=m;
day=d;
}
void nextday();
void display()
{
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
};
void Date::nextday()
{
int totaldays[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};day++;int leap=(year%400==0||year%4==0&&year%100!=0);
if(day>totaldays[leap][month-1])
{
day=1;
month++;
if(month>12)
{
month=1;
year++;
}
}
}
void main()
{
int d,m,y;
cout<<"请输入年、月、日:\n";
cin>>y>>m>>d;
Date d1(y,m,d);
cout<<"今天是:";
d1display();
d1nextday();
cout<<"明天是:";
d1display();
}
#include "stdioh"
main()
{
int year,days=0;
printf("Input year:");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
days=29;
else
days=28;
printf("Days=%d\n",days);
}
以上就是关于关于C语言的问题。设计一个程序,根据用户的选择,将1、日期转换为天数2、将天数转换为日期。全部的内容,包括:关于C语言的问题。设计一个程序,根据用户的选择,将1、日期转换为天数2、将天数转换为日期。、c++程序中,如何定义一个日期Date、c语言程序根据给定的年份计算该年度的二月份的天数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)