C语言题目 编程题? 5
例如:输入 2 28 1 输出3 1 展开
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <ctime>
using namespace std;
int main()
{
tm time1;
int n,m, monthday[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
cin >> time1.tm_mon >> time1.tm_mday >> n;
cout << "输入的日期是:"<<time1.tm_mon << "月" << time1.tm_mday << "日" << endl;
m = n;
if (n >= 365)
n = n - 365;
while (1)
{
if (time1.tm_mday + n <= monthday[time1.tm_mon - 1])
{
time1.tm_mday = time1.tm_mday + n;
break;
}
else
{
time1.tm_mday = time1.tm_mday + n - monthday[time1.tm_mon - 1];
time1.tm_mon++;
n = 0;
}
}
cout <<m<< "天之后日期"<<time1.tm_mon << "月" << time1.tm_mday << "日" << endl;
system("pause");
return 0;
}
2022-12-05 广告