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

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

คำสั่ง switch จะใช้ในกรณีที่มีทางเลือกให้ทำงานหลายทางเลือกโดยใช้เงื่อนไขร่วมกัน ย้ำนะครับว่าเป็นการใช้เงื่อนไขร่วมกัน โดยที่ตัวแปลภาษาจะทำการตรวจสอบเงื่อนไขเพียงครั้งเดียว แต่ผลจากการตรวจสอบจะถูกนำไปพิจารณาทั้งหมดว่าจะทำงานตามทางเลือกใด

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

#include <stdio.h>
main()
{
int day = 7;
switch (day) {
  case 1:
    printf  ("Monday");
    break;
  case 2:
    printf ("Tuesday");
    break;
  case 3:
    printf ("Wednesday");
    break;
  case 4:
    printf ("Thursday");
    break;
  case 5:
    printf ("Friday");
    break;
  case 6:
    printf  ("Saturday");
    break;
  case 7:
    printf ("Sunday");
    break;
}
}

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

Sunday

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