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:05:36

Description: หน่วยที่ 14 คำสั่งเงื่อนไข if

Search

Read the Text Version

AR Book การโปรแกรมคอมพวิ เตอร(Computer Programming) หนว ยท่ี 14 คําส่ังเงอ่ื นไข if จดั ทาํ โดย นายอภิสิทธ์ิ เขตนคร

เน้อื หาสาระพอสังเขปคาํ สัง่ เงื่อนไข คอื คําส่ังทใ่ี ชกําหนดทศิ ทางในการทํางานของโปรแกรม โดยพจิ ารณาจากเงอ่ื นไขท่ีกําหนดในการตดั สนิ ใจ คาํ ส่งั เงือ่ นไข if เปน คาํ ส่งั ตัดสนิ ใจเลอื กทํางานในชุดคําส่งั ที่กําหนดเมอ่ื เงื่อนไขทีต่ รวจสอบเปน จรงิ

รปู แบบท่ี 1 แผนภมู กิ ารทาํ งาน if Condition(Condition) Statement Statement;โดยท่ีCondition คอื เง่อื นไขในการตรวจสอบStatement คือ คาํ สั่งในการทํางานในกรณีการตรวจสอบเงอื่ นไขเปน จรงิ

โปรแกรมการทํางานของคําสงั่ if1 #include <stdio.h>2 #include <conio.h>3 int main ( )4{5 int age;6 printf( \"How old are you? : \");7 scanf(\"%d\", &age );8 if (age < 18 )9 printf (\"You are young \n\" );10 printf(\"You are %d years old \",11 age );12 getch ( );13 return 0;14 }

ผลลัพธของโปรแกรม หนว ยท่ี 14 คําสงั่ เง่อื นไข if if (Condition) Statement ;


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