91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C語言怎么實現基于控制臺的電子時鐘

發布時間:2022-05-05 10:13:27 來源:億速云 閱讀:151 作者:iii 欄目:開發技術

這篇文章主要介紹“C語言怎么實現基于控制臺的電子時鐘”,在日常操作中,相信很多人在C語言怎么實現基于控制臺的電子時鐘問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C語言怎么實現基于控制臺的電子時鐘”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

使用到下面這些技術:

首先必須先導入庫

/***************** 實時數字時鐘(和計算機系統時間關聯) **************
#include <time.h>  -- 必須的時間函數頭文件
time_t -- 時間類型(time.h 定義)
struct tm -- 時間結構,time.h 定義如下:(依需求選用)
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
time(&rawtime); -- 獲取時間,以秒計,從1970年1月一日起算,存于rawtime
                -- 獲取到當前的秒數,參數為0則函數返回值即為結果
localtime(&rawtime); -- 轉為當地時間,tm 時間結構
system("cls");--命令行清屏

獲取坐標的代碼如下

#include <windows.h>
void gotoxy(int x,int y)    //光標定位函數,需要包含windos.h頭文件
{
    COORD coord;
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}

源代碼:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void gotoxy(int x,int y)   //光標定位函數,需要包含windos.h頭文件
{
    COORD coord;
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void dians(){
    int x=8;
    gotoxy(x*3,8);
    printf(" **");
    gotoxy(x*3,9);
    printf(" **");
    gotoxy(x*3,11);
    printf(" **");
    gotoxy(x*3,12);
    printf(" **");
    
    gotoxy(x*6,8);
    printf(" **");
    gotoxy(x*6,9);
    printf(" **");
    gotoxy(x*6,11);
    printf(" **");
    gotoxy(x*6,12);
    printf(" **");
}
void draw_numb(int x,int shu){ //判斷0-9的數據,通過gotoxy顯示出來 
    if(shu==0){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("*   *");
            gotoxy(x,8);
            printf("*   *");
            gotoxy(x,9);
            printf("*   *");
            gotoxy(x,10);
            printf("*   *");
            gotoxy(x,11);
            printf("*   *");
            gotoxy(x,12);
            printf("*   *");
            gotoxy(x,13);
            printf("*   *");
            gotoxy(x,14);
            printf("*****");
    }
    if(shu==1){
            gotoxy(x,6);
            printf("  *  ");
            gotoxy(x,7);
            printf("  *  ");
            gotoxy(x,8);
            printf("  *  ");
            gotoxy(x,9);
            printf("  *  ");
            gotoxy(x,10);
            printf("  *  ");
            gotoxy(x,11);
            printf("  *  ");
            gotoxy(x,12);
            printf("  *  ");
            gotoxy(x,13);
            printf("  *  ");
            gotoxy(x,14);
            printf("  *  ");
    }
    if(shu==2){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("    *");
            gotoxy(x,8);
            printf("    *");
            gotoxy(x,9);
            printf("    *");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("*    ");
            gotoxy(x,12);
            printf("*    ");
            gotoxy(x,13);
            printf("*    ");
            gotoxy(x,14);
            printf("*****");
    }
    if(shu==3){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("    *");
            gotoxy(x,8);
            printf("    *");
            gotoxy(x,9);
            printf("    *");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("    *");
            gotoxy(x,12);
            printf("    *");
            gotoxy(x,13);
            printf("    *");
            gotoxy(x,14);
            printf("*****");
    }
    if(shu==4){
            gotoxy(x,6);
            printf("*   *");
            gotoxy(x,7);
            printf("*   *");
            gotoxy(x,8);
            printf("*   *");
            gotoxy(x,9);
            printf("*   *");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("    *");
            gotoxy(x,12);
            printf("    *");
            gotoxy(x,13);
            printf("    *");
            gotoxy(x,14);
            printf("    *");
    }
    if(shu==5){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("*    ");
            gotoxy(x,8);
            printf("*    ");
            gotoxy(x,9);
            printf("*    ");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("    *");
            gotoxy(x,12);
            printf("    *");
            gotoxy(x,13);
            printf("    *");
            gotoxy(x,14);
            printf("*****");
    }
    if(shu==6){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("*    ");
            gotoxy(x,8);
            printf("*    ");
            gotoxy(x,9);
            printf("*    ");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("*   *");
            gotoxy(x,12);
            printf("*   *");
            gotoxy(x,13);
            printf("*   *");
            gotoxy(x,14);
            printf("*****");
    }
    if(shu==7){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("    *");
            gotoxy(x,8);
            printf("    *");
            gotoxy(x,9);
            printf("    *");
            gotoxy(x,10);
            printf("    *");
            gotoxy(x,11);
            printf("    *");
            gotoxy(x,12);
            printf("    *");
            gotoxy(x,13);
            printf("    *");
            gotoxy(x,14);
            printf("    *");
    }
    if(shu==8){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("*   *");
            gotoxy(x,8);
            printf("*   *");
            gotoxy(x,9);
            printf("*   *");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("*   *");
            gotoxy(x,12);
            printf("*   *");
            gotoxy(x,13);
            printf("*   *");
            gotoxy(x,14);
            printf("*****");
    }
    if(shu==9){
            gotoxy(x,6);
            printf("*****");
            gotoxy(x,7);
            printf("*   *");
            gotoxy(x,8);
            printf("*   *");
            gotoxy(x,9);
            printf("*   *");
            gotoxy(x,10);
            printf("*****");
            gotoxy(x,11);
            printf("    *");
            gotoxy(x,12);
            printf("    *");
            gotoxy(x,13);
            printf("    *");
            gotoxy(x,14);
            printf("*****");
    }    
}
void draws(char wei,int shu){//這里定義了6個位置 分別是小時的個位十位,分鐘的個位十位和秒鐘的個位十位 
int x=8;
        if(wei=='1'){
            draw_numb(x*1,shu);    //這里調用了 draw_numb函數吧x*1是橫坐標(也表示第幾個位置數),shu是要顯示的數據調過去 
        }    //x*1表示第一個位置 
        if(wei=='2'){
            draw_numb(x*2,shu);
        }
        if(wei=='3'){
            draw_numb(x*4,shu);
        }
        if(wei=='4'){
            draw_numb(x*5,shu);
        }
        if(wei=='5'){
            draw_numb(x*7,shu);
        }
        if(wei=='6'){
            draw_numb(x*8,shu);
        }        
}
int main()
{    system("color 1b"); 
    struct tm *curtime;     //結構tm,結構指針curtime,time.h中定義
    time_t t;     //時間類型變量t,time.h中定義
    clock_t start;    //結構clock_t,結構變量start,time.h中定義
    
    double th_hour,th_min,th_sec;
    do
    {    dians();
        t=time(0);    //獲取到當前的秒數,參數為0則函數返回值即為結果
        curtime=localtime(&t);    //得到當前系統時間/
        if((double)curtime->tm_hour<=12)  //午前的處理/
        {    gotoxy(5,3);
            
            printf("AM ");
            //if((double)curtime->tm_hour<10) draws('1',0);   //十點之前在小時數前加零
            draws('1',((int)curtime->tm_hour)/10);
            draws('2',((int)((double)curtime->tm_hour))%10);
        }
        else    //午后的處理
        {    gotoxy(5,3);
            printf("PM ");
            //if((double)curtime->tm_hour-12<10) draws('1',0);//輸入0 
            draws('1',(int)curtime->tm_hour/10);
            draws('2',((int)((double)curtime->tm_hour))%10);
        }
        if((double)curtime->tm_min<10) draws('3',0);
        draws('3',(int)curtime->tm_min/10);
        draws('4',(int)curtime->tm_min%10);
        if((double)curtime->tm_sec<10) draws('5',0);
        draws('5',(int)curtime->tm_sec/10);
        draws('6',(int)curtime->tm_sec%10);
        start=clock();
        while(clock()-start<500);  //等待延時1000ms
        system("cls");
    }while(!kbhit());    //按任一鍵退出   
    return 0;}

最后運行截圖(完美運行)

C語言怎么實現基于控制臺的電子時鐘

到此,關于“C語言怎么實現基于控制臺的電子時鐘”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

渝北区| 收藏| 出国| 兴海县| 清涧县| 罗甸县| 郸城县| 台州市| 丰镇市| 益阳市| 清苑县| 卢氏县| 陆良县| 鲜城| 社旗县| 玛沁县| 峡江县| 浏阳市| 漠河县| 孟连| 柘荣县| 吴川市| 雅江县| 监利县| 荆州市| 旺苍县| 台南县| 太和县| 惠来县| 同仁县| 庄浪县| 邯郸县| 雅江县| 台北市| 昂仁县| 荆州市| 邻水| 郴州市| 龙口市| 盘山县| 庆云县|