最后的棚档printf是不是该%d %d %d???二月的你用润年判断。year%4==0 && year%100!=0 || year%400==0其他的你应该自己知道判断了。。。 还有你的最后一个else里的判断。应该放在每个if判断后。要不你的逻辑就出问题了。你可以试一下,只要你输入每个月最后一天,肯定会输出正确数据。但是,其他的时候,就会出问题。关键是在你的If判链绝乱断出了问题了。#include#include "stdio.h"struct data{int year; int month; int day;};main(){ struct data today,tomorrow; printf("Year: "); scanf("%d",&today.year); printf("Month: "); scanf("%d",&today.month); printf("Day: "); scanf("%d",&today.day);/*每年的最后一天,加一年*/ if(today.month == 12 && today.day == 31){ tomorrow.year = today.year+1; tomorrow.month = 1; tomorrow.day = 1; } /*一个月30天的*/ else if(today.month == 4||today.month == 6||today.month == 9||today.month == 11){ if(today.day == 30){ tomorrow.year = today.year; tomorrow.month = today.month+1; tomorrow.day = 1; } else{ tomorrow.year = today.year; tomorrow.month = today.month; tomorrow.day = today.day + 1; }}/*一个月31天的宏谨*/ else if(today.month == 1 ||today.month == 3||today.month == 5||today.month == 7||today.month == 8||today.month == 10){ if(today.day == 31){ tomorrow.year = today.year; tomorrow.month = today.month+1; tomorrow.day = 1; } else{ tomorrow.year = today.year; tomorrow.month = today.month; tomorrow.day = today.day + 1; } } /*2月份的处理方法。润年29天,否则28天*/ if(today.month==2){ if(today.year%4==0&&today.year%100!=0||today.year%400==0){/*判断是否为润年*/ if(today.day==29){ tomorrow.year = today.year; tomorrow.month = today.month+1; tomorrow.day = 1; } else{ tomorrow.year = today.year; tomorrow.month = today.month; tomorrow.day = today.day + 1; } } else{ if(today.day==28){ tomorrow.year = today.year; tomorrow.month = today.month+1; tomorrow.day = 1; } else{ tomorrow.year = today.year; tomorrow.month = today.month; tomorrow.day = today.day + 1; } } } printf("%d %d %d",tomorrow.year,tomorrow.month,tomorrow.day); system("pause"); return 0;} 这是我改过的完整代码。你看下,行不行。我在dev上运行过没有问题。结果也没有问题。润年的判断,要注意下。另外。。。。劝楼主书写的时候协规范些。。。对以后有好处
标签:C语言,小程序
版权声明:文章由 问百书 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.wenbaishu.com/answer/72684.html