for循环、选择语句 出生日期到现在的天数

#include <stdio.h>

int main()
{
   int birth_y,brith_m,brith_d;

printf("请输入您的出生年月日”);
   scanf("%d%d%d",&birth_y,&brith_m,&brith_d);

   int cur_y,cur_m,cur_d;

printf("请输入现在的年月日”);
   scanf("%d%d%d",&cur_y,&cur_m,&cur_d);

   int  sum=0,sum_y=0,fir=0,end=0;

for(int i=1;i<cur_y-birth_y;i++)//相差年数的有多少天数
{
   if((birth_y+i)%4==0&&(birth_y+i)%100!=0||(birth_y+i)%400==0)
   {
       sum_y += 366;
   }
   else
   {
       sum_y += 365;
   }
}

    switch(cur_m-1)//现在到年初的时间
    {
        case 11:
        fir+=30;
        case 10:
        fir+=31;
         case 9:
        fir+=30;
        case 8:
        fir+=31;
         case 7:
        fir+=31;
        case 6:
        fir+=30;
         case 5:
        fir+=31;
        case 4:
        fir+=30;
        case 3:
        fir+=31;
         case 2:
            if(cur_y%4==0&&cur_y%100!=0||cur_y%400==0)
            {
                fir+=28;
            }
            else
            {
                fir+=29;
            }
        case 1:
        fir+=31;
    }

     switch(brith_m+1)//出生日期到年末的时间
    {
        case 2:
            if(birth_y%4==0&&birth_y%100!=0||birth_y%400==0)
            {
                end+=28;
            }
            else
            {
                end+=29;
            }
        case 3:
        end+=31;
        case 4:
        end+=30;
        case 5:
        end+=31;
        case 6:
        end+=30;
        case 7:
        end+=31;
        case 8:
        end+=31;
        case 9:
        end+=30;
        case 10:
        end+=31;
        case 11:
        end+=30;
        case 12:
        end+=31;
    }


    if(brith_m==1||brith_m==3||brith_m==5||brith_m==7||brith_m==8||brith_m==10||brith_m==12)
    {
        end+=31-brith_d;
    }
    else if(brith_m==4||brith_m==6||brith_m==9||brith_m==11)
    {
        end+=30-brith_d;
    }
    else 
    {
        if(birth_y%4==0&&birth_y%100!=0||birth_y%400==0)
        {
            end+=28-brith_d;
        }
        else
        {
            end+=29-brith_d;
        }
    }

    sum=sum_y+fir+end;

    printf("%d\n",sum);

   
    return 0;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值