c语言用一年总天数减去没有到月份和日算出是一年的多少天?
1个回答
关注
展开全部
do{if(month==2){if(year%400==0||(year%100!=0&&year%4==0)){leapyear=1;month_date[month-1]+=leapyear;}else{month_date[month-1] = 28;}printf("%d年的二月份是:%d天\n",year,month_date[month-1]);}if(sum>month_date[month-1]){sum-=month_date[month-1];month++;if(month==13){year++;month=1;}}} while(sum>month_date[month-1]);day=sum;printf("\n第%d天后是%d-%d-%d",daytime,year,month,day);return 0;}
咨询记录 · 回答于2023-02-07
c语言用一年总天数减去没有到月份和日算出是一年的多少天?
亲,您好,很高兴为您解答。先判断年月日是不是正常数值,计算天数时调用自定义的mon函数得出前月天数和,再加上本月的指定的日期最后输出前判断闰年2月要不要多加一天。
能不能只用if语句和switch语句
mon函数还没学
我把用加法的代码发给你 但是现在我要用减法做 该怎么做
#include#includeint main(){int year,month,day;int leapyear=0;int daytime=0;int sum;int index=0;static int month_date[12]={31,28,31,30,31,30,31,31,30,31,30,31};printf("请输入日期:");scanf("%d-%d-%d",&year,&month,&day);printf("请输入天数:");scanf("%d",&daytime);sum=daytime+day;if(month==2){if(year%400==0||(year%100!=0&&year%4==0)){leapyear=1;month_date[month-1]+=leapyear;}else{month_date[month-1] = 28;}printf("%d年的二月份是:%d天\n",
do{if(month==2){if(year%400==0||(year%100!=0&&year%4==0)){leapyear=1;month_date[month-1]+=leapyear;}else{month_date[month-1] = 28;}printf("%d年的二月份是:%d天\n",year,month_date[month-1]);}if(sum>month_date[month-1]){sum-=month_date[month-1];month++;if(month==13){year++;month=1;}}} while(sum>month_date[month-1]);day=sum;printf("\n第%d天后是%d-%d-%d",daytime,year,month,day);return 0;}
大致减法是这个思路吧,只能给您一点启发。毕竟我是搞硬件的,现在编软件的时候比较少,望见谅。