nextDate C++代码怎么写
时间: 2024-05-02 09:23:33 浏览: 71
以下是一个简单的 nextDate C 代码示例:
```c
#include <stdio.h>
int main() {
int day, month, year;
printf("Please enter a date (DD/MM/YYYY format): ");
scanf("%d/%d/%d", &day, &month, &year);
// Determine if the year is a leap year
int isLeapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
// Determine the maximum number of days in the given month
int maxDays;
if (month == 2) { // February
if (isLeapYear) {
maxDays = 29;
} else {
maxDays = 28;
}
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
maxDays = 30;
} else {
maxDays = 31;
}
// Increment the day
day++;
if (day > maxDays) {
// The day has wrapped around to the next month
day = 1;
month++;
if (month > 12) {
// The month has wrapped around to the next year
month = 1;
year++;
}
}
// Display the next date
printf("The next date is %02d/%02d/%04d.\n", day, month, year);
return 0;
}
```
该程序提示用户输入一个日期,然后计算下一个日期并将其输出。
阅读全文