Cov txheej txheem:

Clock Yooj Yim Hauv Hom Lus C: 4 Cov Kauj Ruam
Clock Yooj Yim Hauv Hom Lus C: 4 Cov Kauj Ruam

Video: Clock Yooj Yim Hauv Hom Lus C: 4 Cov Kauj Ruam

Video: Clock Yooj Yim Hauv Hom Lus C: 4 Cov Kauj Ruam
Video: Cas Tsis Xaiv Koj - R-Lin Thoj New Song Original By Zaj Dub [Official MV] 2023 2024, Hlis ntuj nqeg
Anonim
Clock Yooj Yim Hauv Hom Lus C
Clock Yooj Yim Hauv Hom Lus C

Lub Tswv Yim yog los tsim lub moos yooj yim hauv C, tab sis ua ntej peb yuav tsum teeb tsa peb cov software thiab paub txog qee yam uas peb yuav siv.

Kauj Ruam 1: Kauj Ruam 1:

Kauj ruam 1
Kauj ruam 1
  1. Xaiv Visual Studio, Code Blocks lossis lwm yam software zoo sib xws (kuv xav kom pom qhov muag pom studio 2015).
  2. Kuv yuav siv Visual Studio 2015, yog li ntaus hauv google "Visual Studio 2015 Community", rub tawm thiab teeb tsa.
  3. Tom qab teeb tsa, khiav Visual Studio, nias Tshiab/Project/Console Application.
  4. Hauv Console Application Wizard nias tom ntej, tom qab ntawd xaiv tsis tau Precompiled header thiab xaiv Empty project, ces Finish.
  5. Ntawm koj sab xis koj yuav muaj Solution Explorer, nyem rau ntawm Cov Ntaub Ntawv Ntxiv, Ntxiv/Cov Khoom Tshiab/C ++ cov ntaub ntawv (.cpp), tab sis hloov lub npe rau Source.c thiab ntxiv.
  6. Tam sim no koj muaj C phiaj xwm npaj pib.

Kauj Ruam 2: Kauj Ruam 2: Sau Peb Txoj Cai thiab Kawm Yam Tshiab

Kauj Ruam 2: Sau Peb Txoj Cai thiab Kawm Yam Tshiab
Kauj Ruam 2: Sau Peb Txoj Cai thiab Kawm Yam Tshiab

Nov yog peb tus lej:

#suav nrog#suav nrog // peb suav nrog cov ntawv Windows (nws txuas nrog rau kev ua haujlwm pw tsaug zog ()), uas txhais tau tias qhov no tsuas yog ua haujlwm rau lub qhov rais, yog li yog tias koj siv lwm OS, tshawb hauv google rau lwm yam kev pw tsaug zog ().

int lub ntsiab ()

{

tus, h, m; s. // peb ntxiv cov teev, feeb thiab vib nas this rau peb qhov program

int D = 1000; // peb ntxiv Kev ncua ntawm 1000 milliseconds, uas ua rau thib ob thiab peb yuav siv qhov ntawd hauv kev tsaug zog ().

printf ("Teem sijhawm: / n"); // printf sau rau ntawm cov ntawv screen uas yog sab hauv ("") thiab / n sau ua kab tshiab.

scanf (" %d %d %d", & h, & m, & s); // scanf yog qhov uas peb ntxig peb lub sijhawm, lossis peb qhov tseem ceeb.

yog (h> 12) {printf ("YOOJ YIM! / n"); tawm (0); } // hauv qhov no yog kev ua haujlwm peb tshuaj xyuas yog tias tus nqi nkag tau loj dua 12.

yog (m> 60) {printf ("YOOJ YIM! / n"); tawm (0); } // zoo ib yam ntawm no thiab yog tias nws loj dua, qhov program sau ERROR! thiab tawm mus

yog (s> 60) {printf ("YOOJ YIM! / n"); tawm (0); } // zoo sib xws

thaum (1) // thaum (1) yog lub voj infinity thiab txhua yam hauv rov ua nws tus kheej rau infinity. {

s += 1; // qhov no qhia txoj haujlwm kom nce vib nas this rau 1, txhua lub sijhawm thaum lub sijhawm los txog rau ntu no.

yog (s> 59) {m += 1; s = 0; } // yog tias cov vib nas this ntau dua 59, nws nce cov feeb thiab teev vib nas this rau 0.

yog (m> 59) {h += 1; m = 0; } // zoo sib xws

yog (h> 12) {h = 1; m = 0; s = 0; } // zoo sib xws

printf ("\ n Lub moos");

printf ("\ n%02d:%02d:%02d", h, m, s); // qhov no sau peb lub sijhawm hauv hom ntawv no "00:00:00"

Pw tsaug zog (D); // qhov no yog peb txoj haujlwm pw tsaug zog uas ua rau qeeb lub sijhawm thiab ua rau nws zoo li lub moos.

system ("kws"); // qhov no tshem tawm qhov screen.

}

tau txais (); rov 0;

}

*Txhua yam tom qab '//' yog cov lus tawm tswv yim thiab tsis hloov pauv txoj haujlwm, yog li nws tuaj yeem tshem tawm.

** Visual Studio qee zaum yuav tsis ua haujlwm vim nws muaj "scanf", yog li koj yuav tsum mus rau Kev Tshawb Fawb Explorer> nyem rau ntawm qhov chaw> Cov Khoom (Ib yam li hauv daim duab yuav tsum tshwm sim)> hauv kev teeb tsa xaiv Txhua Qhov Kev Tsim Kho > Cov cuab yeej teeb tsa> C/C ++> Preprocessor> hauv Preprocessor Cov Lus Txhais sau _CRT_SECURE_NO_WARNINGS> Txuag.

Kauj Ruam 3: Kauj Ruam 3: Peb Ruaj Siab Peb Lub Sijhawm Kom Hla Dua Qhov Teeb Meem

Kauj Ruam 3: Peb Ruaj Ntseg Peb Lub Sijhawm Kom Hla Dua Qhov Teeb Meem
Kauj Ruam 3: Peb Ruaj Ntseg Peb Lub Sijhawm Kom Hla Dua Qhov Teeb Meem
  1. Insert random numbers, kom h yog> 12, m yog> 60, s yog> 60.
  2. Txoj haujlwm sau ERROR! thiab tawm mus.
  3. Txog tam sim no vam meej!

Kauj Ruam 4: Kauj Ruam 4:

Kauj ruam 4
Kauj ruam 4
Kauj ruam 4
Kauj ruam 4
  1. Ntxig cov lej tsis raug, yog li h yog <12, m yog <60, s yog <60.
  2. cov lej hloov mus rau 00:00:00 hom ntawv thiab lub moos pib "zuam".
  3. SUCCESS tseeb.

*Tom qab lub moos dhau 12, 'teev' hloov mus rau 01 thiab 'feeb' thiab 'vib nas this' txog 00.

Muaj kev lom zem!

Pom zoo: