标题:小白求教....就学过一点点c语言,想编写一个,相信你们都会的!!!
取消只看楼主
nc不是脑残
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-6-14
结帖率:100%
已结贴  问题点数:10 回复次数:2 
小白求教....就学过一点点c语言,想编写一个,相信你们都会的!!!
编写一个...输入出生日期(农历、新历都可以)就可以知道活了多少天,多少小时??大神们求教了.....谢谢你们!!
搜索更多相关主题的帖子: 出生日期 c语言 
2013-08-09 00:12
nc不是脑残
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-6-14
得分:0 
回复 3楼 小小程序猿
恩恩.谢谢啦..就是闰年这里有点卡....还有就是农历怎么计算就不知道啦..
2013-08-12 21:06
nc不是脑残
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-6-14
得分:0 
回复 2楼 love云彩
#include <stdio.h>
int js(int x,int y,int z)
{
     int i;
     int day0=0;
     int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
     int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
     if(z==0)
     {
             for(i=0;i<=y-1;i++)
             day0=day0+a[i];
             return day0+x;
             }
     else
     {
             for(i=0;i<=y-1;i++)
             day0=day0+b[i];
             return day0+x;
             }
    }
int main(void)
{
     int year[2];
     int mon[2];
     int day[2];
     int day0=0;
     int day1,day2;
     int i;
     int z;

     printf("enter your date of birth\n");
     scanf("%d%d%d",&year[0],&mon[0],&day[0]);

     printf("enter the date now\n");
     scanf("%d%d%d",&year[1],&mon[1],&day[1]);
     
     if(i%4==0)  
       {     
            z=0;  
            day1=js(day[0],mon[0],z);
            day0=366-day1;
            }
        else
       {
            z=1;  
            day1=js(day[0],mon[0],z);
            day0=365-day1;
            }
     
     for(i=year[0]+1;i<=year[1];i++)
     {
                                                              
        if(i==year[1])
           {
            if(year[1]%4==0)
            {
              z=0;
              day2=js(day[1],mon[1],z);
              day0=day0+day2;
              break;
                       }
            if(year[1]%4!=0)
            {
              z=1;
              day1=js(day[0],mon[0],z);
              day2=js(day[1],mon[1],z);
              day0=day0+day2;
              break;
                       }
                               }
                     
                     
        if(i%4==0)     
            day0=day0+366;
        else
            day0=day0+365;
                        
                                  }
     printf("%d",day0);
     }
有哪里不对...
2013-08-12 21:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-418827-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.110599 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved