1 / 14

Gestructureerd programmeren in C

Gestructureerd programmeren in C. GESPRG Les 3. Herhalen. Herhalen. Er zijn in C 3 herhalingsopdrachten for do while while. In het boek wordt niet uitgelegd wanneer je welke herhalingsopdracht moet gebruiken!. for.

meryl
Download Presentation

Gestructureerd programmeren in C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gestructureerd programmeren in C GESPRG Les 3

  2. Herhalen

  3. Herhalen • Erzijn in C 3herhalingsopdrachten • for • do while • while In het boek wordt niet uitgelegd wanneer je welke herhalingsopdracht moet gebruiken!

  4. for • Gebruikeenforals het aantalherhalingenbij het programmeren “bekend” is. doe telkens aan einde #include<stdio.h> intmain(void) { inti; for(i = 1; i != 10; i = i + 1) { printf("hallo %d\n", i); } getchar(); return0; } zolang… initialisatie Uitvoer?

  5. Relationeleoperatoren: Vergelijken Resultaat is eenint (waar 1, onwaar  0) Let op verschil in C tussen = en ==

  6. Alternatievevoorwaarde #include<stdio.h> intmain(void) { inti; for(i = 1; i < 10; i = i + 1) { printf("hallo %d\n", i); } getchar(); return0; } Is dit beter ? Wat gebeurt er als i = i + 2 wordt gebruikt?

  7. { bla; bla; bla; } • Compound statement. • Alseen compound statement uitslechts1 statement bestaatdan kun je ookalleendatene statement gebruiken. #include<stdio.h> intmain(void) { inti; for(i = 1; i < 10; i = i + 1) printf("hallo %d\n", i); getchar(); return0; } Is dit aan te raden?

  8. Inspringen • Maak je programmaleesbaar door netjes in tespringen. Er zijn verschillende veel gebruikte manieren. Kies zelf maar blijf wel consequent! #include<stdio.h> intmain(void) { inti; for(i = 1; i < 10; i = i + 1) { printf("hallo %d\n", i); } getchar(); return0; } http://en.wikipedia.org/wiki/Indent_style

  9. 1+2+3+…+100 =? #include<stdio.h> intmain(void) { inti, som = 0; for(i = 1; i <= 100; i = i + 1) { som = som + i; } printf("som = %d\n", som); getchar(); return0; } ??? Kan dit slimmer? http://nl.wikipedia.org/wiki/Somformule_van_Gauss

  10. do while • Gebruikeendo whileals het aantalherhalingenbij het programmeren “onbekend” en ≥1 is. #include<stdio.h> intmain(void) { intgetal; do{ printf("Geef een positief getal: "); scanf("%d", &getal); } while(getal <= 0); printf("Het ingevoerde getal = %d\n", getal); fflush(stdin); getchar(); return0; } zolang…

  11. while • Gebruikeenwhileals het aantalherhalingenbij het programmeren “onbekend” en ≥0 is. #include<stdio.h> intmain(void) { intgetal; printf("Geef een positief getal: "); scanf("%d", &getal); while(getal <= 0) { printf("Nee dombo! Geef een positief getal: "); scanf("%d", &getal); } printf("Het ingevoerde getal = %d\n", getal); fflush(stdin); getchar(); return0; } zolang…

  12. Huiswerk • Schrijfeenprogrammadat de tafels van 1 t/m 5 netjesnaastelkaarafdrukt. • Bestudeer C boek: • paragraaf 1.6. • paragrafen 4.1 t/m 4.3. • paragraaf 4.5. • paragrafen 4.8 t/m 4.10. • paragrafen 4.12 en 4.13. • Maakopdrachten: • 7 en 10 van paragraaf 1.12.

  13. Herhaal (strafwerk)

  14. Programmeren == Moeilijk ? • Schrijfeenprogrammadat… • Hoe bedenk je eenprogramma? • Stapvoorstap… • Stapgewijzeverfijning • http://bd.eduweb.hhs.nl/gesprg/tafels_stap_voor_stap.htm Programmeren = De computer vertellen wat hij moet doen, schreeuwen helpt niet!

More Related