Upcoming SlideShare
×

# การเขียนคำสั่งควบคุมแบบวนซ้ำ กลุ่ม 4 ม.6 ห้อง2

313 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
313
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

### การเขียนคำสั่งควบคุมแบบวนซ้ำ กลุ่ม 4 ม.6 ห้อง2

1. 1. 1. 1.1 Increment Operator 4.1 ++ increment 1 b=3 ; a=b ++ 1 2 a=b; a=3 b=b+1;b=3+1
2. 2. b=3 ; a=++b 1. 2 b=b+1; b=3+1 a=b; a=4 2. a 4 b 4 -- decrement 11.2 decrement operator 4.2
3. 3. b=3 a=b - - 1. 2a=b; a=3 b=b-1; b=3-1 2. a 3 b 2 a= - -b 1. 2
4. 4. 1.3 (compound assignmentoperators) 4.3
5. 5. 1.4
6. 6. a = b ++ ; 2 a=b; b aa=4 a=b+1 ; 4+1 5 b b=5 b = ++ a ; a=a+1; a 4 4+1
7. 7. 1.5 implicit typeconversionexplicit type conversion
8. 8. 4.3
9. 9. 4.3 4.31. result 1 = value1 + value 2 ; 10 + 3.17 13.17result 12. result 1 = value / 3 ; / % .2f
10. 10. 2 for :3 : for For ( = ; ;2.1 ) {for statemmnt (s) ; } for : 1
11. 11. 4.1 for2.2 for 5
12. 12. 4.4 for
13. 13. 1. 52. n 13. n 64.
14. 14. 2.3 for 4.5 for
15. 15. 4.54.512. 3 33.
16. 16. 3. while : while {} while {} while
17. 17. while while >{}
18. 18. 3.2 while while
19. 19. Ctrl-Break n <= 5 n n
20. 20. while while whilen <= 5 n = n+1 ;
21. 21. while nwhile n
22. 22. nnum
23. 23. do-while
24. 24. do – while do – while do – whil
25. 25. do – whiledo – while
26. 26. {} while n <= 5n>5 n++ : n=n +1: n n>5
27. 27. {} do – while
28. 28. do – while n
29. 29. • for• while• do- while
30. 30. Forfor 2 3 for
31. 31. nkey loop =>……………Report Score****************************No. => ……………name is => …………..midterm is => …………..Final is => ……………* Score = ……………******************************Average Score is = ………….*****************************
32. 32. 1. 1.1 1.2 = 1 = = = 1.3
33. 33. 1.5 num n name midterm
34. 34. 1.6 action) 1 (num) 2) for (n =1; n<=num ;n++) 2.1-2.6 3 2.1) (n) 2.2) (name) (midterm) (final) 2.3) (score) =midterm + final 2.4) score 2.5) (sum) = sum +score 2.6) 2 3) (average) = sum / num
35. 35. start2. num For (n = 1 ; n <= num ; n++) n > num n <= num n Averge = sum / num name,midterm,final average Score = midterm + final end score sum = sum + score
36. 36. 3. #include <stdio.h> /* file name ex_for3.cpp*/ main () { char name [30] ; int midterm = 0 , final = 0 , score = 0 ,n , num ; float sum = 0 , average = 0 ; printf (“ key loop => “) ; scanf (“%d “,&num) ; Printf (“n Report Score n”) ; printf(“*************************n n”) ; for(n = 1;n <= num ; n++) { printf ({“No. => %d n” , n) ; printf (“Name is => “) ; scanf (“%s”,name) ; printf (“midterm is => “) ; scanf (“%d”&midterm) ; printf (“final is => “) ; scanf (“%d”&final) ; score = midterm =+ final; printf ( “* score = %dn”,score) ; sum = sum + score ; printf (“*****************n”) ; } average = sum / num ; printf (“* Averge score is = %.2f n” , averge) ; printf (“***********************n) ; }
37. 37. while for whileendless loop)
38. 38. while
39. 39. while while statement ; while{ ; ; ;} while
40. 40. #include <stdio.h>int counter , num;char word[20] = "Bodindecha";main(){ num = 0; counter = 3; while ( counter <= 11){ printf("ntcounter = %2d my school is %s printround %d. ",counter,word,++num); counter = counter + 2 ; }getch();}
41. 41. numcounter while counter <= 11 printf("ntcounter = %2d my school is %s print round %d. ",counter,word,++num); counter = counter + 2countercounter counter <= 11
42. 42. do-while do while loop)while do while endless loop)
43. 43. do while
44. 44. do whileDo { ; ; ;} while ;
45. 45. #include <stdio.h>int counter ,num ;char word[20] = "Bodindecha";main(){ Num = 0;counter = 3;do /*start do while */{ printf("ntcounter = %2d my school is %s printround %d. ",counter,word,++num); counter = counter + 2 ; } while (counter < 11 ); /*end do while */getch();}/* end main() */
46. 46. counter do whileprintf("ntcounter = %2d my school is %s print round %d. ",counter,word,++num); counter = counter + 2;counter < 11 counter
47. 47. for
48. 48. while{} {}
49. 49. do -while {}1while
50. 50. 10 28 29 32 33 34 356/2