我寫了個好麻煩的代碼,運行失敗找不到原因
#include <stdio.h>
int main()
{
??? /* 定義需要計算的日期 */
??? int year = 2008;
??? int month = 8;
??? int day = 8;
???? int result;
???? int temporary;
switch(year%4)
{
??? case 0:
??????? result+=1;
??????? if(month>2||month<8);
??????? {
???????????
??????????? if(month%2==0);
??????????? {
??????????????? result+=month/2*31+(month/2-1)*30+28;
??????????????? printf("result");
??????????? }
??????????? else
??????????? {
??????????????? result+=(month/2+1)*31+(month/2-1)30+28;
??????????????? printf("result");
??????????? }
??????? }
??????? else if(month<2||month>0)
??????? {
??????????? result+=31;
??????????? printf("result");
??????? }
??????? else if(month==2)
??????? {
??????????? result+=31+28;
???????????? printf("result");
??????? }
??????? else if(month>=8)
??????? {??
???????????
??????????? month-7=temporary;
???????????
??????????? result+=(month/2+1)*31+(month/2-1)30+28;
???????????
????????????? if(temporary%2==0)
?????????????? {
??????????????? result+=temporary/2*31+(temporary/2-1)*30+28;
???????????????? printf("result");
?????????????? }
?????????????? else
?????????????? {
??????????????? result+=(temporary/2+1)*31+(temporary/2-1)30+28;
???????????????? printf("result");
?????????????? }
??????? }
???
???
???
???
??? default:
??? printf("%s\n"," 我失敗了");
}
?return 0;
}
2019-10-29
修改后
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
??? /* 定義需要計算的日期 */
??? int year = 2008;
??? int month = 8;
??? int day = 8;
???? int result=0;
???? int temporary=0;
switch(year%4)
{
??? case 0:
??????? result+=1;
??????? if(month>2||month<8)
??????? {
??????????? if(month%2==0)
??????????? {
??????????????? result+=month/2*31+(month/2-1)*30+28+day;
??????????????? printf("%d",result);
??????????????? break;
??????????? }
??????????? else
??????????? {
??????????????? result+=(month/2+1)*31+(month/2-1)*30+28+day;
??????????????? printf("%d",result);
??????????????? break;
??????????? }
??????? }
??????? else if(month<2||month>0)
??????? {
??????????? result+=31+day;
??????????? printf("result");
??????????? break;
??????? }
??????? else if(month==2)
??????? {
??????????? result+=31+28+day;
???????????? printf("result");
???????????? break;
??????? }
??????? else if(month>=8)
??????? {
??????????? month-=7;
?????????? temporary=month;
?????????? month+=7;
??????????? result+=((month/2+1)*31+(month/2-1)*30+28)+day;
????????????? if(temporary%2==0)
?????????????? {
??????????????? result+=temporary/2*31+(temporary/2-1)*30+28+day;
???????????????? printf("result");
???????????????? break;
?????????????? }
?????????????? else
?????????????? {
??????????????? result+=(temporary/2+1)*31+(temporary/2-1)*30+28+day;
???????????????? printf("result");break;
?????????????? }
??????? }
??????? else
??????? {
??????? printf("%s\n","這里什么都沒有");
??????? }
??? default:
??? printf("%s\n"," 母雞啊");
}
?return 0;
}
2019-10-29
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
??? /* 定義需要計算的日期 */
??? int year = 2008;
??? int month = 8;
??? int day = 8;
???? int result=0;
???? int temporary=0;
switch(year%4)
{
??? case 0:
??????? result+=1;
??????? if(month>2||month<8)
??????? {
??????????? if(month%2==0)
??????????? {
??????????????? result+=month/2*31+(month/2-1)*30+28+day;
??????????????? printf("%d",result);
??????????????? break;
??????????? }
??????????? else
??????????? {
??????????????? result+=(month/2+1)*31+(month/2-1)*30+28+day;
??????????????? printf("%d",result);
??????????????? break;
??????????? }
??????? }
??????? else if(month<2||month>0)
??????? {
??????????? result+=31+day;
??????????? printf("result");
??????????? break;
??????? }
??????? else if(month==2)
??????? {
??????????? result+=31+28+day;
???????????? printf("result");
???????????? break;
??????? }
??????? else if(month>=8)
??????? {
??????????? month-=7;
?????????? temporary=month;
?????????? month+=7;
??????????? result+=((month/2+1)*31+(month/2-1)*30+28)+day;
????????????? if(temporary%2==0)
?????????????? {
??????????????? result+=temporary/2*31+(temporary/2-1)*30+28+day;
???????????????? printf("result");
???????????????? break;
?????????????? }
?????????????? else
?????????????? {
??????????????? result+=(temporary/2+1)*31+(temporary/2-1)*30+28+day;
???????????????? printf("result");break;
?????????????? }
??????? }
??????? else
??????? {
??????? printf("%s\n","這里什么都沒有");
??????? }
??? default:
??? printf("%s\n"," 母雞啊");
}
?return 0;
}