zoukankan      html  css  js  c++  java
  • C_时间段计算代码

    #include "StdAfx.h"
    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
        int a,b,c,d,e,f,g,h,i;  
       
    ///////////////////输入起始时间///////////////////////
        while(1)
        {
        system("cls");                                             //清屏函数 
        while(1){                                                     //输入日期
        printf("请您输入起始时间,日:") ; 
        scanf("%d",&a);
        if(a<=31)                                                   //数据合法性判断
            break;
        else
            printf("输入错误,请重新输入
    ");
         }
        while(1){                                                     //输入时间
        printf("请您输入起始时间,时:") ; 
        scanf("%d",&b);
        if(b<=24)
            break;
        else
            printf("输入错误,请重新输入
    ");
         }
        while(1){                                                      //输入分钟
        printf("请您输入起始时间,分:") ; 
        scanf("%d",&c);
        if(c<=60)
            break;
        else
            printf("输入错误,请重新输入
    ");
         }
    /////////////////输入终止时间////////////////
            while(1){                                                    
        printf("
    
    请您输入终止时间,日:") ; 
        scanf("%d",&d);
        if( d<=31&&d>=a)                            //此处同时判断终止日期是否大于起止日期                                    
            break;
        else
            printf("输入错误,请重新输入
    ");
         }
        while(1){                                                    
        printf("请您输入终止时间,时:") ; 
        scanf("%d",&e);
        if(e<=24)
            break;
        else
            printf("输入错误,请重新输入
    ");
         }
        while(1){                                                     
        printf("请您输入终止时间,分:") ; 
        scanf("%d",&f);
        if(f<=60)
            break;
        else
            printf("输入错误,请重新输入
    ");
         }
        ///////进行加减运算///////////
        if(f>=c)                                       //先从分钟数开始减
            i=f-c;
        else
        {
            i=f+60-c;
            e=e-1;
        }
    
        if(e>=b)                                       //再从时钟数开始减
            h=e-b;
        else
        {
            h=e+24-b;
            d=d-1;
        }
                             
        g=d-a;                                        //再从天数开始减,前面已作判断,此处直接相减
        
        printf("
    
    两个时间相差:  %d天  %d时  %d分
    ",g,h,i);
        system("pause");                        //暂停函数
        
        }
    
        
        return 0;
    }
    生命的意义在于学习,学习让生活变得精彩
  • 相关阅读:
    常用注解
    代码自动生成插件:
    jsoup爬虫技术+druid连接池

    图书管理系统-项目介绍
    shiro
    (C#) What is the difference between "const" and "static readonly" ?
    What is a Windows USB device path and how is it formatted?
    (C/C++ interview) Static 详解
    Cpk
  • 原文地址:https://www.cnblogs.com/gougouwang/p/13294483.html
Copyright © 2011-2022 走看看