为了账号安全,请及时绑定邮箱和手机立即绑定

我写了个好麻烦的代码,运行失败找不到原因

#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;
}


正在回答

2 回答

修改后

#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;
}


0 回复 有任何疑惑可以回复我~

#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;
}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

我写了个好麻烦的代码,运行失败找不到原因

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信