| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 285 人关注过本帖
标题:请教C大大一个问题,谢谢大虾解答!
只看楼主 加入收藏
wszhhx
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-18
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
请教C大大一个问题,谢谢大虾解答!
我编了一个可以将数据在(年,天,时,分,秒)这些单位间任意转换的程序。
程序代码是这样的:
#include<stdio.h>
main()
{
    float a,b;
    int X;
    int c,d,y1,y2,l;
    char d1,d2;
    c=0;
    printf("请输入任意时间数字部分\n");
    scanf("%f",&a);
    printf("请输入你所键入数据的单位,年(y),天(d),时(h),分(m),秒(s)\n");
    scanf("%c\n",&d1);
    printf("请输入您所需要转换的时间单位\n");
    scanf("%c\n",&d2);
    if (d1=='y')
    {
        if (d2=='d')     /*年转化为天*/
        {
            printf("请确定这些年为公元几几年到几几年\n");
            scanf("%d %d",&y1,&y2);
            l=y1;
            while (l<=y2)
            {
                if (l%4==0)
                {
                    c+=1;
                }
                else
                {
                    c+=0;
                }
                l+=1;
            }
            b=c*366+365*(a-c);
            printf("%d年到%d年一共有%d天\n",y1,y2,b);
        }
        else if (d2=='h')   /*年转化为小时*/
        {
             while (l<=y2)
            {
                if (l%4==0)
                {
                    c+=1;
                }
                else
                {
                    c+=0;
                }
                l+=1;
            }
            printf("在%d年到%d年之间一共隔着%d小时\n",y1,y2,(long int)8784*c+8760*(a-c));
        }
        else if (d2=='m')   /*年转化为分钟*/
        {
            while (l<=y2)
            {
                if (l%4==0)
                {
                    c+=1;
                }
                else
                {
                    c+=0;
                }
                l+=1;
            }
            printf("在%d年到%d年之间共隔着%ld\n",y1,y2,(long int)366*24*60*c+365*24*60*(a-c));
        }
        else if (d2=='s')   /*年转化为秒*/
        {
           while (l<=y2)
            {
                if (l%4==0)
                {
                    c+=1;
                }
                else
                {
                    c+=0;
                }
                l+=1;
            }
                printf("在%d年与%d年之间隔着%d秒\n",y1,y2,(long int)366*24*60*60*c+365*24*60*60*(a-c));
        }
        else
        {
            printf("您输入了非法数据\n");
        }
    }
    else if (d1=='d')
    {


        if (d2=='y')
        {
            y1=a/365;
            y2=a-y1*365;
            b=a/365;
            printf("%f天等于%d年零%d天,也等于%f年\n",a,y1,y2,b);
            printf("由于只有天数无法识别有几个闰年,所以默认用365天计算,请谅解~\n");
        }
        else if (d2=='h')
        {
            b=a*24;
            printf("%f天等于%f小时\n",a,b);
        }
        else if (d2=='m')
        {
            b=a*24*60;
            printf("%f天等于%分钟\n",a,b);
        }
        else if (d2=='s')
        {
            b=a*24*60*60;
            printf("%f天等于%秒\n",a,b);
        }
        else
        {
            printf("您输入了非法数据\n");
        }
    }
    else if (d1=='h')
    {


        if (d2=='y')
        {
            b=a/24/365;
            printf("%f小时等于%f年\n",a,d);
            printf("由于只有天数无法识别有几个闰年,所以默认用365天计算,请谅解~\n");
        }
        else if (d2=='d')
        {
            b=a/24;
            printf("%f小时等于%f天\n",a,b);
        }
        else if (d2=='m')
        {
            b=a*60;
            printf("%f小时等于%f分钟\n",a,b);
        }
        else if (d2=='s')
        {
            b=a*60*60;
            printf("%f小时等于%f秒\n",a,b);
        }
        else
        {
            printf("您输入了非法数据\n");
        }
    }
    else if (d1=='m')
    {


        if (d2=='y')
        {
            b=a/60/24/365;
            printf("%f分钟等于%f年\n",a,b);
            printf("由于只有天数无法识别有几个闰年,所以默认用365天计算,请谅解~\n");
        }
        else if (d2=='d')
        {
            b=a/60/24;
            printf("%f分钟等于%天\n",a,b);
        }
        else if (d2=='h')
        {
            b=a/60;
            printf("%分钟等于%f小时\n",a,b);
        }
        else if (d2=='s')
        {
        b=a*60;
        printf("%f分钟等于%f秒\n",a,b);
        }
        else
        {
            printf("您输入了非法数据\n");
        }
    }
    else if (d1=='s')
    {


        if (d2=='y')
        {
            b=a/60/60/24/365;
            printf("%f秒等于%f年\n",a,b);
            printf("由于只有天数无法识别有几个闰年,所以默认用365天计算,请谅解~\n");
        }
        else if (d2=='d')
        {
            b=a/60/60/24;
            printf("%f秒等于%f天\n",a,b);
        }
        else if (d2=='h')
        {
            b=a/60/60;
            printf("%f秒等于%f小时\n",a,b);
        }
        else if (d2=='m')
        {
            b=a/60;
            printf("%f秒等于%f小时\n",a,b);
        }
        else
        {
            printf("您输入了非法数据\n");
        }
    }
    else
        {
            printf("您输入了非法数据\n");
        }

}
  程序运行测试结果如下:
请输入任意时间数字部分
24
请输入你所键入数据的单位,年(y),天(d),时(h),分(m),秒(s)
h
请输入您所需要转换的时间单位
d
您输入了非法数据

Process returned 0 (0x0)   execution time : 9.573 s
Press any key to continue.
搜索更多相关主题的帖子: include 
2013-10-18 11:04
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
好长   不知道你想问什么

DO IT YOURSELF !
2013-10-18 11:09
wszhhx
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-18
收藏
得分:0 
回复 2楼 wp231957
我编了一个可以将数据在(年,天,时,分,秒)这些单位间任意转换的程序
为什么会出现最后那个测试结果??求解,谢谢!
2013-10-18 11:16
qunxingw
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:24
帖 子:1676
专家分:7295
注 册:2011-6-30
收藏
得分:10 
数据类型都末统一,     b=c*366+365*(a-c);
            设计太长,末细看

www.qunxingw.wang
2013-10-18 11:26
快速回复:请教C大大一个问题,谢谢大虾解答!
数据加载中...
 
   



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

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