求各位大神幫我看一下哪里有問(wèn)題,為什么輸出來(lái)的是221
#include <stdio.h>
int main()
{
??? /* 定義需要計(jì)算的日期 */
??? int year = 2008;
??? int month = 8;
??? int day = 8;
?
??? int sum ;
??? switch (month)
??? {
??????? case 1:sum=0;break;
??????? case 2:sum=31;break;
??????? case 3:sum=59;break;
??????? case 4:sum=90;break;
??????? case 5:sum=120;break;
??????? case 6:sum=151;break;
??????? case 7:sum=181;break;
??????? case 8:sum=212;break;
??????? case 9:sum=243;break;
??????? case 10:sum=273;break;
??????? case 11:sum=304;break;
??????? case 12:sum=334;break;
??????? default:
??????? printf("%s\n","一年只有12個(gè)月");
??????? break;
??? }
??? if(year%4==0&&year%100!=0&&month>=2)
??? {
??????? sum+=1 ;
??? }
???
??? else
??? {
???????? sum ;
??? }
???
? sum+=day ;
printf("2008年是該年的第%d天",sum) ;
?return 0;
2019-07-21
首先你算法有問(wèn)題。其次,答案是對(duì)的2008年8月8日是2008年的第221天。
2019-07-21
╮(╯-╰)╭還是有點(diǎn)弄不懂,有點(diǎn)懵
2019-07-21
題目要求的是用switch和if-else語(yǔ)句來(lái)編寫該程序,結(jié)果提示我輸出錯(cuò)誤,我用筆算了一下是223,你寫的語(yǔ)句太超前了,我還沒(méi)學(xué)到那里,所以有點(diǎn)理解不了~~
2019-07-21
改成這樣了 你看怎么樣
#include <stdio.h>
int main()?
{?
? ? int year = 2008 ;
? ? int month = 8 ;
? ? int day = 8 ;
? ? int a[]={0,31,59,90,120,151,181,212,243,273,304,334} ;
? ? int sum ;
if(month>=0&&month<=12)
sum=a[month-1] ;
sum+=day ;
? ? if(((year%4==0&&year%100!=0)||year%400==0)&&month>=2)
? ? {
? ? ? ? sum+=1 ;
? ? }??
printf("%d年%d月%d日是該年的第%d天",year,month,day,sum) ;
return 0 ;
}
2019-07-21
可否告知算法哪里出錯(cuò)了?我這個(gè)思路沒(méi)毛病啊