日期显示:输入今天的日期,输出明天的日期。
时间: 2023-11-02 11:07:55 浏览: 155
根据提供的引用内容,可以编写一个程序来实现输入今天的日期,输出明天的日期的功能。具体实现方法如下:
1. 首先定义一个结构体来存储日期信息,包括年、月、日。
2. 使用引用中的代码提示用户输入今天的日期。
3. 使用引用和引用中的代码来计算明天的日期,并将结果存储在一个新的日期结构体中。
4. 最后输出明天的日期。
代码示例:
```
#include <stdio.h>
struct Date {
int year;
int month;
int day;
};
int numberOfDays(struct Date date) {
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (date.month == 2) {
if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0) {
return 29;
} else {
return 28;
}
} else {
return daysInMonth[date.month - 1];
}
}
struct Date tomorrow(struct Date today) {
struct Date tomorrow;
if (today.day != numberOfDays(today)) {
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
} else {
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
if (tomorrow.month > 12) {
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
return tomorrow;
}
int main() {
struct Date today, nextDay;
printf("Enter today's date(mm dd yyyy): ");
scanf("%i %i %i", &today.month, &today.day, &today.year);
nextDay = tomorrow(today);
printf("Tomorrow's date is %i/%i/%i.\n", nextDay.month, nextDay.day, nextDay.year);
return 0;
}
```