C++输入年月日,输出第二天是什么

本文介绍了一个简单的C++程序,该程序接收用户输入的日期(年月日格式),并计算出输入日期的第二天具体是哪一天。通过判断是否为闰年及各个月份的天数来准确得出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

输入年月日,输出第二天是什么

#include <iostream.h>
#include <string.h>
struct date
{
int year,month,day;
};
int is_leap_year(struct date *pd){
int flag=0;
if ((pd->year%4==0&&pd->year%100!=0)||pd->year%400==0)
{
flag=1;
}
return flag;
}
int number_of_days(struct date *pd){
int day=0;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (is_leap_year(pd)&&pd->month==2)
{
day=29;
}else{
day=days[pd->month];
}
return day;
}


void main(){
struct date today,tomorrow;
cout<<"输入年月日(yyyy-mm-dd):"<<endl;
cin>>today.year>>today.month>>today.day;
if (today.day!=number_of_days(&today))
{
tomorrow.year=today.year;
tomorrow.month=today.month;
tomorrow.day=today.day+1;
}
else if (today.month==12)
{
tomorrow.year=today.year+1;
tomorrow.month=1;
tomorrow.day=1;
}
else{
tomorrow.year=today.year;
tomorrow.month=today.month+1;
tomorrow.day=1;
}
cout<<tomorrow.year<<'-'<<tomorrow.month<<'-'<<tomorrow.day<<endl;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值