經(jīng)典C語言程序設(shè)計(jì)100例(9)

字號(hào):

【程序91】
    題目:時(shí)間函數(shù)舉例1
    1.程序分析:
    2.程序源代碼:
    #include "stdio.h"
    #include "time.h"
    void main()
    { time_t lt; /*define a longint time varible*/
    lt=time(NULL);/*system time and date*/
    printf(ctime(<)); /*english format output*/
    printf(asctime(localtime(<)));/*tranfer to tm*/
    printf(asctime(gmtime(<))); /*tranfer to Greenwich time*/
    }
    -----------------------------------------------------------------------------
    【程序92】
    題目:時(shí)間函數(shù)舉例2
    1.程序分析:           
    2.程序源代碼:
    /*calculate time*/
    #include "time.h"
    #include "stdio.h"
    main()
    { time_t start,end;
    int i;
    start=time(NULL);
    for(i=0;i<3000;i++)
    { printf("\1\1\1\1\1\1\1\1\1\1\n");}
    end=time(NULL);
    printf("\1: The different is %6.3f\n",difftime(end,start));
    }
    -----------------------------------------------------------------------------
    【程序93】
    題目:時(shí)間函數(shù)舉例3
    1.程序分析:
    2.程序源代碼:
    /*calculate time*/
    #include "time.h"
    #include "stdio.h"
    main()
    { clock_t start,end;
    int i;
    double var;
    start=clock();
    for(i=0;i<10000;i++)
    { printf("\1\1\1\1\1\1\1\1\1\1\n");}
    end=clock();
    printf("\1: The different is %6.3f\n",(double)(end-start));
    }