ดาวน์โหลดงานนำเสนอ
งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ
ได้พิมพ์โดยKrittayot Jurangkool ได้เปลี่ยน 9 ปีที่แล้ว
1
886201 หลักการโปรแกรม 1 Lecture 9: การทำซ้ำ (for)
2
ทบทวนเรื่อง while
3
ทบทวนเรื่อง do-while
4
The for Statement Syntax for (ForInit ; ForExpression; PostExpression) Action Example for ( int i = 0; i < 3; i++ ) { cout << “i is " << i << endl; }
6
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i 0
7
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i 0
8
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i 0
9
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i 0
10
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i 1
11
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i 1
12
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i 1
13
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i 1
14
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i 2
15
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i 2
16
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i is 2 i 2
17
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i is 2 i 2
18
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i is 2 i 3
19
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i is 2 i 3
20
Execution Trace for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl; } cout << "all done" << endl; i is 0 i is 1 i is 2 all done i 3
21
Example: หาผลรวมของเลข 1 ถึง 10 T F i=i+1 i<=10 sum = sum+i i = 1 sum = 0 sum = 0; for (int i=1; i <= 10; i++ ) sum += i; RESULT: sum =1+2+3+...+10
22
Example: พิมพ์เลขคี่ที่อยู่ในช่วง 1 ถึง 10 T F i+=2 i < 10 i = 1 print i for (int i=1; i<10; i+=2) cout << i << “ ”; RESULT: 1 3 5 7 9
23
Example: พิมพ์ค่า 10 ลงมาจนถึง 1 i = 10 print i i=i-1 T F i>=1 for (int i=10; i >= 1; i--) cout << i << “ ”;
24
initialization condition statements update for (int count = 1; count <= 10; count++) { cout << count << endl; } int count = 1; // Initialize the counter while (count <= 10) // Check the counter { cout << count << endl; count++; // Update the counter } initialization condition statements update while vs. for
25
แบบฝึกหัด ให้เขียนโปรแกรมเพื่อแสดงค่า x 2 + x – 4 เมื่อ x=5, 6, …,12 ให้เขียนโปรแกรมเพื่อแสดงสูตรคูณแม่ 5
งานนำเสนอที่คล้ายกัน
© 2024 SlidePlayer.in.th Inc.
All rights reserved.