C语言题目:设计一个程序输入年月日 输出下一天的年月日 要C语言,不要C++

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言题目:设计一个程序输入年月日 输出下一天的年月日 要C语言,不要C++相关的知识,希望对你有一定的参考价值。

#include
"stdio.h"
int
isleapyear(int
year);//判断是不是闰年。
int
iscurrentdate(int
year,int
month,int
day);//是不是正确的日期。
int
returnnextday(int
year,int
month,int
day);//返回下一天,也有判断是不是正确的日期。
int
leapyear_month_sumday[12]=31,29,31,30,31,30,31,31,30,31,30,31;//闰年数组,保存各月天数。
void
main()

int
year=0,month=0,day=0,nextday=0;
printf("pleace
enter
right
date(example:2005
6
27):\n");
scanf("%d%d%d",&year,&month,&day);
nextday=returnnextday(year,month,day);
switch
(nextday)

case
0:
printf("not
a
current
date\n");
break;
case
1:
if
(month==12)

year++;
month=1;

else

month++;

break;

if
(nextday!=0)
printf("the
you
input
next
date
is
%d-%d-%d.thank
use
bye
bye!\n",year,month,nextday);

int
isleapyear(int
year)

if
(year%4==0)

if
(year%400)
return
1;
else

if
(year%100==0)
return
0;
else
return
1;


else

return
0;


int
iscurrentdate(int
year,int
month,int
day)

if
((year<0)
&&
(year>9999)
&&
(month>12)
&&
(month<1)
&&
(day<1)
&&(day>31)
)return
0;
else
return
1;

int
returnnextday(int
year,int
month,int
day)

int
thismonthsumday;
if
(iscurrentdate(year,month,day)==1)

thismonthsumday=leapyear_month_sumday[month-1];
if
(month==2)

if
(isleapyear(year)==0)
thismonthsumday--;

if
(day<thismonthsumday)

return
++day;

else

if
(day==thismonthsumday)

return
1;

else

return
0;



else

return
0;

参考技术A day);


/.month+(today;
ltd[2]=29,4;).month])%13.\
unsigned
char
day
;);
if(today;
tomorrow;n",&today;
else
if((today;
tomorrow,31;
ltd[0]=0,30,tomorrow;n":2011.year,30;%d,31,1\.day),29;错误的日期输入;
以上程序经TURBO
C验证,tomorrow.month])
printf("ltd[today;请输入日期.month==2)&&((today;.month]+1),格式如.year,%d.year%100)==0))
printf(".year=today!=0))
ltd[2]=28;
printf("
else
ltd[0]=1,%d.month==2)&&((today;
;ltd[today;/);
scanf(".month.day==29)&&(today,30.month==0)
tomorrow,31,"%d;错误的日期输入.month])/13;n".year%100==0))||(today.month.month=1;
if(tomorrow.\,%d",30.year%4.day+1)%(ltd[today.day=1;
tomorrow.day=(today;
while(1)

while(.day==0)
tomorrow.year%4==0)&&(today,31;
unsigned
char
month
,tomorrow;
else
if((today.day+1)/,31!ltd[0])

printf("ltd[today.\
if(tomorrow;

if(((today.month+(today!=0))
printf(",31.month=(today,%d.month==2)&&(today,&today.year+(today.year%4),&today;错误的日期输入.day+1)/.day>,31;)#include
".h"stdio;
date
today;n".day==29)&&(today,tomorrow
;
void
main()

unsigned
char
ltd[13]=0;
struct
date

unsigned
short
year本回答被提问者采纳
参考技术B 31;*日期结构*/,31;

unsigned
year."year>n"
unsigned
month;<,31;*判断是否是闰年*/,28.month
==
13)/
bValidDate
=
IsValidDate(*pDate).day
;".month;
nextDay
=
date,30.year<,month
and
day
:
28;

return
((year%4
==
0)
&&
(year%100
;
Date
nextDay;<"<\
while(;
if(date;:
"pDate->



void
NextDay(void)

static
unsigned
char
dayOfMonth[12]
=
31;

static
unsigned
char
dayOfMonth[12]
=
31;
return
(date;<
unsigned
day;

int
main(void)

NextDay();<

else

nextDay.day<"
++nextDay,31!bValidDate)

cout<=
12)
&&
(date;
?
29
.month
=
1;

bool
bValidDate
=
false;
inline
bool
IsLeapYear(unsigned
year)/,31,30:
28;
InputDate(&date)."*判断时期是否合法*/*到了下一年*/
if(nextDay#include
<,30.year;nextDay.day;!\*判断是否是本月的最后一天*/
struct
Date/.year)
,31,30;
++nextDay,31;;

void
InputDate(Date
*pDate)/nextDay;The
next
day
is
,输入不合法会被要求再次输入*/
dayOfMonth[1]
=
IsLeapYear(date;month>=
dayOfMonth[date,31;<:\,31;
return
0;>,30,30.month<,30;<,30,28;
dayOfMonth[1]
=
IsLeapYear(date.month-1]);Please
input
year.day
bValidDate)

cout<nextDay;<">?
29
.month
<
if(!=
dayOfMonth[date;pDate-
day;<
cin>


cout<<*输入日期;n"pDate->
Date
date;iostream>">.month-1])/

++nextDay;"<.day
=
1,31;
评论
0
0
加载更多

以上是关于C语言题目:设计一个程序输入年月日 输出下一天的年月日 要C语言,不要C++的主要内容,如果未能解决你的问题,请参考以下文章

C语言输入年月日,判断第几天的问题最后计算是第几天出错了

用c 语言编写程序:根据输入的年、月、日,求出该日是这一年中的第几天?

输入年月日判断这一天是这一年的第几天 ?(C语言编写)!

java如何获取某一天的日期?

用C语言输入年月日,输出距今天还有多少天,星期几,是不是是公历节日

C语言的问题:根据输入的年月日,输出该日为该年度的第几周、第几天、星期几。