Yuav ua li cas qeeb hauv C: 7 Cov Kauj Ruam (nrog Duab)

Cov txheej txheem:

Yuav ua li cas qeeb hauv C: 7 Cov Kauj Ruam (nrog Duab)
Yuav ua li cas qeeb hauv C: 7 Cov Kauj Ruam (nrog Duab)

Video: Yuav ua li cas qeeb hauv C: 7 Cov Kauj Ruam (nrog Duab)

Video: Yuav ua li cas qeeb hauv C: 7 Cov Kauj Ruam (nrog Duab)
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Tej zaum
Anonim

Koj puas tau xav ua qhov program C tos rau qee lub sijhawm?

Koj tuaj yeem teeb tsa cov txheej txheem los tso cai rau lub sijhawm zuam tawm, piv txwv li: thaum pom nplooj ntawv tawg (ceeb toom lossis qhia) rau kev ua si.

Okay, ntawm no yog qee txoj hauv kev los ua kom txoj haujlwm "sawv tseem", nyeem ntawm …

Cov kauj ruam

Ncua hauv C Kauj Ruam 1
Ncua hauv C Kauj Ruam 1

Kauj Ruam 1. Ua kom koj lub CPU ua haujlwm rau qee lub sijhawm yam tsis muaj qhov tshwm sim tshwm sim

Ncua hauv C Kauj Ruam 2
Ncua hauv C Kauj Ruam 2

Kauj Ruam 2. Tsis txhob ua lwm txoj haujlwm thaum lub sijhawm ncua ntawd, txhawm rau tsim lub sijhawm yooj yim-ncua

Txoj Kev 1 ntawm 2: Cov txheej txheem "rau-voj"

Ncua hauv C Kauj Ruam 3
Ncua hauv C Kauj Ruam 3

Kauj Ruam 1. Siv qhov raug "rau" lub voj ua raws los ntawm kab lus hais tsis zoo los siv sijhawm ncua

Ncua hauv C Kauj Ruam 4
Ncua hauv C Kauj Ruam 4

Kauj Ruam 2. Sau raws li hauv qab no, ua piv txwv:

  • rau (kuv = 1; kuv <100; kuv ++);
  • Cov lus hais tom qab ";" ua rau lub khoos phis tawj ua haujlwm lub voj 100 zaug yam tsis muaj qhov xwm txheej pom tau. Nws tsuas yog tsim lub sijhawm ncua.

Txoj kev 2 ntawm 2: Tus txheej txheem "pw tsaug zog ()"

Ncua hauv C Kauj Ruam 5
Ncua hauv C Kauj Ruam 5

Kauj Ruam 1. Siv kev pw tsaug zog () Lub luag haujlwm hu ua pw tsaug zog (int ms) tshaj tawm uas ua rau txoj haujlwm tos rau lub sijhawm hauv milliseconds teev

Ncua hauv C Kauj Ruam 6
Ncua hauv C Kauj Ruam 6

Kauj Ruam 2. Suav kab hauv qab no hauv koj qhov program ua ntej "int main ()":

#suav nrog

Ncua hauv C Kauj Ruam 7
Ncua hauv C Kauj Ruam 7

Kauj Ruam 3. Ntxig, txhua qhov chaw koj xav tau koj qhov program kom ncua:

  • tsaug zog (1000);
  • Hloov qhov "1000" rau tus lej ntawm lub milliseconds koj xav tos (piv txwv li, yog tias koj xav ua kom ncua sijhawm thib ob thib ob, hloov nws nrog "2000".
  • Tswv yim: Ntawm qee lub tshuab tus nqi yuav xa mus rau vib nas this, tsis yog milliseconds. Yog li qee zaum 1000 tsis yog thib ob, tab sis, qhov tseeb, 1000 vib nas this.

Lub tswv yim

  • Cov laj thawj saum toj no tuaj yeem ua tiav los ntawm kev siv ib qho kev ua haujlwm looping ua raws los ntawm cov lus hais tseg- ";", zoo li siv thaum lossis ua-thaum loops.
  • Ib lub millisecond yog 1/1000 ntawm ob.

Lus ceeb toom

  • Cov txheej txheem no feem ntau tsis muaj txiaj ntsig dab tsi ntxiv rau txoj haujlwm tsis tseem ceeb. Feem ntau, siv cov timers lossis cov txheej xwm uas tau tshwm sim los ua qhov no. Txwv tsis pub txoj haujlwm yuav dhau los tsis teb thaum lub sijhawm ncua, thiab qhov ntawd tsis yog qhov zoo ib txwm. Dhau li, xaiv N hauv koj lub voj, yog tias nws nyob ntawm kev qhia ua haujlwm, tej zaum yuav muaj txiaj ntsig tshwm sim. Thaj tus sau thawj zaug yeej tsis tau hnov dua ntawm qhov ua kom zoo tshaj plaws compiler … nws tuaj yeem ua kom zoo dua tag nrho lub voj yog tias nws tsis ua dab tsi!
  • Yog tias koj tab tom siv rau-lub voj, tus sau ntawv tuaj yeem ua kom zoo dua cov cai, thiab, vim tias lub voj tsis ua dab tsi, tshem nws. Qhov no tsis tshwm sim thaum siv qeeb ().
  • Nco ntsoov tias thaum siv cov txheej txheem rau-lub voj, koj yuav xav tau qhov loj heev rau kuv, vim tias cov lus hais tsis tiav tau ua tiav nrawm heev. Cov lej loj li no yuav tsis haum rau hauv hom ua lej.

Pom zoo: