วิชาการเขียนโปรแกรมด้วยภาษาซี (c)

คำสั่ง if ภาษาซี c programming

คำสั่ง if ภาษาซี (c) ใช้ในการควบคุมทิศทางการทำงานของโปรแกรม เป็นการควบคุมแบบเลือกทำ นำมาประยุกต์ใช้ในการตัดสินใจกระทำสิ่งใดสิ่งหนึ่ง

  • คำสั่ง if จะเลือกทำกรณีเดียวทำนั้น
  • โครงสร้าง if(เงื่อนไข) คำสั่งที่จะให้ทำกรณีเงื่อนไขเป็นจริง สามารถใส่คำสั่งได้มากกว่า 1 ก็ได้ แต่ให้อยู่ภายใน { }

ตัวอย่างคำสั่ง if ภาษาซี (c)

#include <stdio.h>
main()
{
	int a =20;
	int b =30;
	if (a<b)
        {
	printf("%d",a);
        }
}

ผลลัพธ์ที่ได้

20


คำสั่ง if ซ่อน if

#include <stdio.h>
main()
{
	int a =20;
	int b =30;
	int c =10;
	if (a<b){
	        if (a>c){
		printf("b>a>c= %d",a);
	}
	}
}

ผลลัพธ์ที่ได้

b>a>c= 20

 

slot gacor hari ini slot qris slot gacor maxwin slot online slot gacor gampang menang slot gacor hari ini slot online slot slot slot guci777 guci777 fafatogel fafatogel fafatogel fafatogel agen138 slot agen138 slot data hk bola slot bolaslot99 bola slot agen138 link alternatif koin138 link alternatif agen138 slot ag138 slot slot gacor slot thailand