Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore 7) คำสั่งวนซ้ำ while for

7) คำสั่งวนซ้ำ while for

Published by Peerawit, 2021-11-11 04:16:21

Description: 7) คำสั่งวนซ้ำ while for

Search

Read the Text Version

ตัวอยา่ งการใช้ #include<iostream> 0 1 using namespace std; i=4 2 3 int main(){ 4 4 for(int i=0; 4 < 5 ;i++){ i=4+1 cout<<i<<endl; } return 0; }

ตัวอยา่ งการใช้ 0 1 #include<iostream> 2 3 using namespace std; i=5 4 int main(){ for(int i=0; 4 < 5 ;i++){ i=4+1 cout<<i<<endl; } return 0; }

ตัวอยา่ งการใช้ 0 1 #include<iostream> 2 3 using namespace std; i=5 4 int main(){ for(int i=0; 4 < 5 ;i++){ cout<<i<<endl; } return 0; }

ตวั อยา่ งการใช้ #include<iostream> 0 1 using namespace std; i=5 2 3 int main(){ 2 4 for(int i=0;i5 < 5 ;i++){ cout<<i<<endl; } return 0; }

ตัวอยา่ งการใช้ #include<iostream> 0 1 using namespace std; i=5 2 3 int main(){ false 4 for(int i=0;i5 < 5 ;i++){ cout<<i<<endl; } return 0; }

ตัวอยา่ งการใช้ #include<iostream> 0 1 using namespace std; i=5 2 3 int main(){ false 4 for(int i=0;i5 < 5 ;i++){ cout<<i<<endl; } return 0; }

โจทยต์ วั อยา่ ง 1)เขยี นโปรแกรมแสดงตัวเลข 1 ถึง n โดยรับ n จากผใู้ ช้ 2)เขยี นโปรแกรมบวกเลขจํานวน ตงั แต่ 1ถงึ n โดยรับ n จากผู้ใช้ 3)เขยี นโปรแกรมบวกจาํ นวนคู่ ตังแต่ 1 ถึง n โดยรับ n จากผ้ใู ช้ 4)เขยี นโปรแกรมเพ่ือรบั จํานวนคน และคะแนนสอบ (คะแนนเตม็ 100) เมอื่ รบั คะแนนครบตามจํานวนแล้ว ใหแ้ สดงวา่ มีนกั เรียนผ่าน และตกก่คี น (เกณฑ์การผ่านคือคะแนนตังแต่50 ขนึ ไป)

คาํ สัง่ ควบคุมแบบวนซาํ 2 (for)

do while loop

รูปแบบคาํ ส่ัง do while do{ ถา้ เงอ่ื นไขเป็นจรงิ (คา่ ของนพิ จน์ ชุดคําสัง่ 1 ; เปน็ true) จะเขา้ ไปทําคําส่ัง ภายในลูป หลงั do{ } }while(เงอ่ื นไข);


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook