zoukankan      html  css  js  c++  java
  • 自定义的TIME.H头文件

     1 //no.1 leap():if leap:return=1;else:return=0;
     2 //no.2 sum_day(oy,om,od,ny,nm,nd):return=s;
     3 //no.3 sum_second(int h,int m,long s):return=s;
     4 //no.4 delay(int n):no return
     5 //no.5 countdown(unsigned long s):no return
     6 //no.6 timing(unsigned long s):no return
     7 #ifndef __TIME_H__
     8 #define __TIME_H__
     9 #include <stdio.h>
    10 //no.1
    11 int leap(int a)
    12 {
    13 if(a%4==0&&a%100!=0||a%400==0)
    14 return 1;
    15 else
    16 return 0;
    17 }
    18 //no.2
    19 int sum_day(int oy,int om,int od,int ny,int nm,int nd)
    20 {
    21 int i;
    22 long s=0;
    23 int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    24 int b[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    25 for(i=oy;i<ny;i++)
    26 if(leap(i)==0)
    27 s+=365;
    28 else
    29 s+=366;
    30 for(i=om-2;i>=0;i--)
    31 {if(leap(oy)==0)
    32 s-=a[i];
    33 else
    34 s-=b[i];
    35 s-=od;
    36 }
    37 for(i=nm-2;i>=0;i--)
    38 if(leap(ny)==0)
    39 s+=a[i];
    40 else
    41 s+=b[i];
    42 s+=nd;
    43 return s;
    44 }
    45 //no.3
    46 long sum_second(int h,int m,long s)
    47 {
    48 s=3600*h+60*m+s;
    49 return s;
    50 }
    51 //no.4
    52 void delay(int n)
    53 {
    54     int i;
    55     n*=50000000;
    56     for(i=1;i<=n;i++);
    57 }
    58 //no.5
    59 void countdown(unsigned long s)
    60 {
    61 int i;
    62 unsigned long n;
    63 n=s;
    64 for(i=0;i<=s;i++)
    65 {printf(" %9ld秒!",n);
    66 delay(6);
    67 if(i<s)
    68 printf("");
    69 n--;
    70 }
    71 }
    72 //no.6
    73 void timing(unsigned long s)
    74 {
    75 int i;
    76 unsigned long n;
    77 n=0;
    78 for(i=0;i<=s;i++)
    79 {printf(" %9ld秒!",n);
    80 delay(6);
    81 if(i<s)
    82 printf("");
    83 n++;
    84 }
    85 }
    86 #endif
  • 相关阅读:
    asp.net core 不依赖autofac实现aop
    C# 获取调用者信息
    IIS 命令学习
    Jenkins + PowerShell + .net core 自动打包
    gogs 自定义配置
    搜索文件内容神器:SearchMyFiles
    非常强大的磁盘计算大小工具:TreeSizeFree
    rancher入门教程
    IQueryable 表达式解析学习
    Sql server 入门权威指南
  • 原文地址:https://www.cnblogs.com/wangyishan/p/6904668.html
Copyright © 2011-2022 走看看