C語言學習:心形小程序代碼實現

前言:編程

學了這麼久的C語言,你是否是有不少會寫的小玩意了呢?好比說簡單的五角星,三角形,等腰三角形,心形之類的~筆者今天發現了個之前寫的一個很好玩的小程序分享給你們~~小程序

心形小程序

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

代碼以下:

#include<stdio.h> windows

#include<math.h> ide

#include<windows.h> 學習

#include<time.h> 3d

#include<stdlib.h> 視頻

voidsetcolor(unsigned shortforecolor,unsigned shortbackgroundcolor) blog

教程

    handle hcon=getstdhandle(std_output_handle); get

    setconsoletextattribute(hcon,(forecolor%16)|(backgroundcolor%16*16)); 

intmain() 

    floatx,y; 

    ints=0,n,i,j; 

        for(i = 1;i <= 50;i++) 

    { 

        setcolor(0,14); 

        printf(" "); 

        printf("%d%%",2*i); 

        sleep(101-2*i); 

        printf("\b\b\b"); 

    } 

    setcolor(15,0); 

    printf("\b\n加載完成!即將進入:"); 

    sleep(2000); 

    system("cls"); 

    do

    { 

        system("color 0e"); 

        for(i=0;i<=56;i++) 

    { 

        if(i>=20){printf("*");sleep(10);} 

        elseprintf(" "); 

    }printf("\n"); 

    for(i=0;i<=56;i++) 

    { 

        if(i>=20){printf("*");sleep(10);} 

        elseprintf(" "); 

    } 

    printf("\n\t\t\t你想要怎樣的心形:\n"); 

    printf("\n\t\t\t1:由love組成的心形!\n"); 

    printf("\n\t\t\t2:由隨機字符組成的心形!\n"); 

    printf("\n\t\t\t3:由隨機數字組成的心形!\n"); 

    printf("\n\t\t\t4:由隨機顏色組成的心形!\n"); 

    printf("\n\t\t\t5:退出!\n"); 

    for(i=0;i<=56;i++) 

    { 

        if(i>=20){printf("*");sleep(10);} 

        elseprintf(" "); 

    }printf("\n"); 

    for(i=0;i<=56;i++) 

    { 

        if(i>=20){printf("*");sleep(10);} 

        elseprintf(" "); 

    } 

    printf("\n\t\t\t"); 

    srand(time(null)); 

    scanf("%d",&n); 

    system("cls"); 

        switch(n) 

            { 

        case1: 

    for(x=1.3;x>=-1.1;x-=0.1) 

    {   for(y=-2;y<=1.4;y+=0.053) 

        { 

            if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0) 

            { 

                s++; 

                if(s%4==1)printf("l"); 

                if(s%4==2)printf("o"); 

                if(s%4==3)printf("v"); 

                if(s%4==0)printf("e"); 

                sleep(2); 

            } 

            else

                printf(" "); 

        } 

    printf("\n"); 

    } 

    printf("繪製完成,按任意鍵返回主頁面!");break; 

    case2: for(x=1.3;x>=-1.1;x-=0.1) 

    {   for(y=-2;y<=1.4;y+=0.053) 

        { 

            if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0) 

            { 

                printf("%c",rand()%10+rand()%10+97); 

                sleep(2); 

            } 

            else

                printf(" "); 

        } 

    printf("\n"); 

    } 

    printf("繪製完成,按任意鍵返回主頁面!");break; 

    case3:for(x=1.3;x>=-1.1;x-=0.1) 

    {   for(y=-2;y<=1.4;y+=0.053) 

        { 

            if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0) 

            { 

                printf("%d",rand()%10); 

                sleep(2); 

            } 

            else

                printf(" "); 

        } 

    printf("\n"); 

    } 

    printf("繪製完成,按任意鍵返回主頁面!");break; 

        case4: for(x=1.3;x>=-1.1;x-=0.1) 

    {   for(y=-2;y<=1.4;y+=0.053) 

        { 

            if(pow(x*x+y*y-1,3)-x*x*x*y*y<=0) 

            { 

                setcolor(0,rand()%6+10); 

                printf(" "); 

                sleep(2); 

            } 

            else

            {setcolor(0,0); 

            printf(" ");} 

        } 

    printf("\n"); 

    } 

    setcolor(15,0); 

    printf("繪製完成,按任意鍵返回主頁面!");break; 

        default:break; 

        }    

        getch(); 

        system("cls"); 

    }while(n!=5); 

}

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 


另外若是你想更好的提高你的編程能力,學好C語言C++編程!彎道超車,快人一步!筆者這裏或許能夠幫到你~

UP在主頁上傳了一些學習C/C++編程的視頻教程,有興趣或者正在學習的小夥伴必定要去看一看哦!會對你有幫助的~

分享(源碼、項目實戰視頻、項目筆記,基礎入門教程)

歡迎轉行和學習編程的夥伴,利用更多的資料學習成長比本身琢磨更快哦!

免費學習書籍:

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

免費學習資料:

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

相關文章
相關標籤/搜索