Hloov cov xim thiab cov ntawv hauv C program tuaj yeem pab nws sawv tawm thaum khiav los ntawm tus neeg siv. Hloov cov xim ntawm cov ntawv thiab cov khoom yog cov txheej txheem ncaj ncaj, thiab cov haujlwm tsim nyog tau npaj muaj nyob hauv cov tsev qiv ntawv tus qauv. Koj tuaj yeem hloov xim twg koj tsim ntawm qhov screen.
Kauj ruam
Ntu 1 ntawm 2: Hloov Cov Ntawv Luam Tawm Xim
Kauj Ruam 1. Suav nrog Cov Qauv Qiv Tawm thiab Tso Tawm
Lub tsev qiv ntawv dav dav no tso cai rau koj hloov xim uas cov ntawv tso tawm pom. Ntxiv cov cai hauv qab no saum koj qhov haujlwm:
#suav nrog
Kauj Ruam 2. Suav nrog Console Cov Tswv Yim thiab Cov Ntawv Tso Tawm
Cov kauj ruam no yuav ua kom yooj yim dua los ntes cov keyboard nkag los ntawm cov neeg siv. Ntxiv cov tsev qiv ntawv hauv qab stdio.h lub tsev qiv ntawv:
#ncig #ncig
Kauj Ruam 3. Siv cov ntawv xim ua kom pom cov xim twg koj xav siv rau cov ntawv
Koj tuaj yeem siv txoj haujlwm no txhawm rau hloov xim ntawm koj cov ntawv sau. Cov xim yuav tsum tau sau rau hauv txhua lub kaus mom, lossis qhia raws li tus lej lej:
#suav nrog #suav nrog lub ntsiab () {textcolor (RED); // Koj tuaj yeem ntaus "4" hloov "RED", tab sis nws nyuaj rau pom}
Xim | Tus Zauv Tus Nqi |
---|---|
Dub | 0 |
Xiav | 1 |
GREEN | 2 |
SIAB | 3 |
Liab | 4 |
MAGENTA | 5 |
CHOCOLATE | 6 |
LOJ GRAY | 7 |
QHOV TSEEB | 8 |
XEEB XEEB | 9 |
LIGHT GREEN | 10 |
SIAN YOUNG | 11 |
PINK | 12 |
YAWG MAGENTA | 13 |
YELLOW | 14 |
DAWB | 15 |
Muaj ntau ntau xim. Cov xim muaj nyob ntawm qhov teeb tsa cov duab tsav tsheb thiab hom tam sim no. Cov xim yuav tsum tau sau ua txhua daim ntawv loj
Kauj Ruam 4. Ntxiv cov ntawv tso tawm thiab ua tiav qhov haujlwm
Suav nrog cprintf ua haujlwm los tso saib qee cov ntawv nrog koj cov xim tshiab. Siv qhov ua haujlwm getch thaum kawg kaw qhov haujlwm thaum tus neeg siv nias ib qho tseem ceeb.
#suav nrog #suav nrog lub ntsiab () {textcolor (RED); // Koj tuaj yeem ntaus "4" hloov "RED", tab sis nws nyuaj rau lees paub cprintf ("Nyob Zoo, Ntiaj Teb!"); nqa (); rov 0; }
Ntu 2 ntawm 2: Hloov Duab Xim
Kauj Ruam 1. Suav nrog lub tsev qiv ntawv duab
Lub tsev qiv ntawv C duab tso cai rau koj kos cov khoom ntxiv nrog rau kho lawv cov xim. Koj tuaj yeem nkag mus rau lub tsev qiv ntawv duab los ntawm suav nrog nws nyob rau sab saum toj ntawm koj qhov haujlwm:
#suav nrog
Kauj Ruam 2. Suav nrog Console Cov Tswv Yim thiab Cov Ntawv Tso Tawm
Koj tuaj yeem siv lub tsev qiv ntawv no los ua kom yooj yim dua rau ntes cov neeg siv khoom. Ntxiv cov tsev qiv ntawv hauv qab lub tsev qiv ntawv graphics.h:
#ncig #ncig
Kauj Ruam 3. Teem cov kev hloov pauv rau cov duab tsav tsheb thiab hom
Koj yuav tsum ua cov kauj ruam no ua ntej koj pib kos cov khoom kom cov program tuaj yeem nkag mus rau lub kaw lus tsav tsheb. Cov kauj ruam no yuav tsim thaj tsam ntawm lub vijtsam uas kos cov khoom.
#include #include main () {int gd = DETECT, gm; initgraph (& gd, & gm, "C: / TC / BGI"); // Hloov qhov no rau koj qhov chaw nyob compiler}
Kauj Ruam 4. Txiav txim siab qhov xim ntawm qhov khoom koj xav kos
Ua ntej coding ib yam khoom, siv setcolor muaj nuj nqi los qhia cov xim ntawm cov khoom kom kos:
#include #include main () {int gd = DETECT, gm; initgraph (& gd, & gm, "C: / TC / BGI"); setcolor (XEEB); // Koj tuaj yeem nkag "1" hloov "BLUE" kom tau txais cov xim zoo ib yam, tab sis nws nyuaj rau pom}
Kauj Ruam 5. Kos lub hom phiaj uas koj xaiv
Piv txwv li, koj kos ib lub xwmfab uas siv cov duab plaub. Koj tuaj yeem siv cov cuab yeej siv duab kos duab los xaiv xim.
#include #include main () {int gd = DETECT, gm; initgraph (& gd, & gm, "C: / TC / BGI"); setcolor (XEEB); duab plaub (50, 50, 100, 100); // Daim duab no qhia qhov chaw nyob ntawm kaum sab xis saum thiab hauv qab}
Kauj Ruam 6. Ua kom tiav qhov kev zov me nyuam thiab khiav qhov kev xeem
Ntxiv qhov hais kom ua thiab kaw thaj tsam duab thaum koj kaw qhov program. Sau thiab sim.
#include #include main () {int gd = DETECT, gm; initgraph (& gd, & gm, "C: / TC / BGI"); setcolor (XEEB); duab plaub (50, 50, 100, 100); nqa (); kaw kab lus (); rov 0; }
Piv txwv
#include #include main () {int gd = DETECT, gm, drawing_color; char [100]; initgraph (& gd, & gm, '' C: / TC / BGI ''); drawing_color = xim (); sprintf (a, '' Cov duab teeb duab tam sim no = %d '', drawing_color); outtextxy (10, 10, a); nqa (); kaw kab lus (); rov 0; }