嗨我刚刚开始在大学学习C语言。现在我面临着一个我不知道如何解决的问题。到目前为止,我们只使用了 库,没有别的,scanf也是我们下周要学的 。现在我们只是使用printf来处理所有事情。 我已经学会如何说如果一年是闰年,但是,我的任务是下一个:需要创建一个程序来读取日期并打印出第二天的日期,输出如下:阅读日期并打印出第二天日期的C程序
Enter a date in the form day month year: 17 5 2010
The date of the next day is: 18/5/2010
我的困境是,我不知道要使用什么操作或如何设置代码以确保考虑闰年,例如如果今天的日期是28 2 2010年下一个日期需要是1 3 2010年,因为它不是闰年。 使用的唯一库并没有scanf函数,但(与scanf函数还) 到目前为止,我得到这个:
#include <stdio.h>
int day, month, year, ndays, leapdays;
bool leapyear;
int main() {
day = 28;
month = 2;
year = 2010;
ndays = day + 1;
leapdays = 31;
leapyear = false;
if (leapyear % 4 == 0) {
leapyear = true;
}
if (leapyear % 100 == 0) {
leapyear = false;
}
if (leapyear % 400 == 0) {
leapyear = true;
}
if ((leapyear) && (month == 12 || month == 1 || month == 3 || month == 5
|| month == 7 || month == 8 || month == 10)) {
leapdays = 31;
}
if ((leapyear) && (month == 4 || month == 6 || month == 9 || month == 11
)) {
leapdays = 30;
}
if ((leapyear) && (month == 2)) {
leapdays = 29;
} else if ((leapyear == false) && (month == 2)) {
leapdays = 28;
}
printf ("Enter a date in the form day month year: %d %d %d \n", day,
month, year);
printf ("The date of the next day is: %d/%d/%d", ndays, month, year);
}
如果你不能使用'scanf'你打算如何获得输入? –
你不输入,你只需创建变量并在其周围改变它 –
你不需要喊,但是你确实需要处理你的问题描述,因为它说'需要创建一个读取日期的程序'和你的printf请求输入。 –