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-09 09:20:25

Description: หน่วยที่ 8 ตัวดำเนินการเปรียบเทียบ

Search

Read the Text Version

AR Book การโปรแกรมคอมพวิ เตอร (Computer Programming)หนวยที่ 8 ตวั ดาํ เนินการเปรยี บเทยี บ (Relational Operators) จดั ทําโดย นายพนั กร แกวบุดตา

เนอ้ื หาสาระพอสงั เขปตัวดําเนินการเปรยี บเทียบ ตัว ดํ าเ นิน ก าร เป รีย บ เทีย บ ใ ช สํ าห รั บเปรยี บเทยี บขอมูล 2 คา ที่อยูดานซายและดานขวาของตัวดําเนินการ โดยผลลัพธท่ีไดจะออกมาเพียงสองคา เทา นั้น คือ 1 แทนคา จริง และคา 0 คา เทจ็

ตวั ดําเนนิ การ ศัพทเ ฉพาะ ความหมาย < Less than นอ ยกวา <= Less than or นอ ยกวา หรือ equal to เทากบั > Greater than มากกวา >= Greater than มากกวา หรือ or equal to เทา กับ == Equal to เทา กับ != Not equal to ไมเ ทากับ

ตัวอยา ง แสดงการคําน วณตัวดําเนินการเปรียบเทียบโดยกําหนดให a, b และ c เปนตัวแปรจาํ นวนเตม็ มคี า เปน 5, 10, และ 15 ตามลําดับนิพจนท างตรรกะตอ ไปน้จี ะใหผ ลเปน ดงั น้ี นพิ จน ผล คาท่ไี ด a<b จริง 1( b+c )>(a +35) เทจ็ 0 b == 10 จริง 1 c != 15 เทจ็ 0

โปรแกรม แสดงการใชตัวดาํ เนนิ การเปรยี บเทยี บ 1 #include<stdio.h> 2 3 int main( ) 4 { int a=5, b=10,c=15; 5 /* less than */ 6 printf(\"a < b is %d\n\",a<b); 7 printf(\"-2.5 < -2.0 is %d\n\",-2.5<-2.0); 8 printf(\"'b' < 'a' is %d\n\n\",'b'<'a'); 910 /* less than or equal to */11 printf(\"c <=(a+b) is %d\n\",c<=(a+b));12 printf(\"-2. <= -2.0 is %d\n\",-2.<=-2.0);13 printf(\"'a' <= 'b' is %d\n\n\",'a'<='b');14 /* greater than */

15 printf(\"a > b is %d\n\",a>b);16 printf(\"2e10 > 23e-10 is %d\n\",2e10 > 23e-10);17 printf(\"'b' > 'a' is %d\n\n\",'b'>'a');1819 /* greater than or equal to */20 printf(\"c >=(a+b) is %d\n\",c>=(a+b));21 printf(\"2. >= -2.0 is %d\n\",-2.>=-2.0);22 printf(\"'c' >= 'b' is %d\n\n\",'c'>='b'+1);2324 /* equal to and not equal to */25 printf(\"(a+5)== b is %d\n\",(a+5)== b);26 printf(\"(a+5)!= b is %d\n\",(a+5)!= b);27 getch( );28 return 0;29 }

หนว ยที่ 8 ตัวดําเนินการเปรยี บเทียบ < <= > >= == !=


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