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 การโปรแกรมคอมพิวเตอร์

การโปรแกรมคอมพิวเตอร์

Published by weerathum, 2018-04-10 10:11:31

Description: หน่วยที่ 16 คำสั่งเงื่อนไข if–else if (nested if)

Search

Read the Text Version

AR Book การโปรแกรมคอมพิวเตอร(Computer Programming)หนวยท่ี 16 คาํ สงั่ เงอ่ื นไข if–else if (nested if) จดั ทําโดย นายฐติ พฒั น ระวชิ ัยภัทรกลุ

เนื้อหาสาระพอสังเขปคําส่ังเงอื่ นไข if–else if (nested if) เปนคําส่ังตัดสินใจเลือกทํางานในชุดคําส่ังใดชุดคําส่ังหนึ่งจากหลายๆ ชุดคําส่ัง ซ่ึงพิจารณาจากเง่อื นไขทีก่ ําหนด โดยพิจารณาเงื่อนไขแรก ถาเปนจริงใหทํางานชุดคําส่ังท่ี 1 และถาเง่ือนไขเปนเท็จใหพิจารณาเง่ือนไขตอไป ทําเชนนี้ตอไป หากพบวาทุกเง่ือนไขเปนเท็จ ใหทํางานในชุดคําส่ังสุดทาย

รปู แบบ แผนภูมกิ ารทํางาน if (Condition 1) Statement1 ; else if(Condition 2) Statement 2; else if(Condition 3) Statement 3; else Statement 4;

โปรแกรม แสดงการทํางานของ if–else if 1 #include <stdio.h> 2 #include <conio.h> 3 int main( ) 4{ 5 int points; 6 7 printf( \"Please enter points : \" ); 8 scanf( \"%d\", &points ); 9 if( points >= 80 ) 10 printf( \"You get grade A\n\" ); 11 else if (points >= 70 ) 12 printf( \"You get grade B\n\" ); 13 else if (points >= 60 ) 14 printf( \"You get grade C\n\" );

15 else if (points >= 50 ) 16 printf( \"You get grade D\n\" ); 17 else 18 printf( \"You get grade F\n\" ); 19 getch ( ); 20 return 0; 21 }ผลลัพธของโปรแกรม หนวยท่ี 16 คําสงั่ เงอ่ื นไข if–else if (nested if)


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