สื่อการสอนการเขียนโปรแกรมภาษาซี ระดับชั้น ม. 6

กลับหน้าหลัก

คำสั่งควบคุมลำดับการทำงาน if/else
รูปแบบ
if  (เงื่อนไข)
{
    คำสั่ง 1;
    คำสั่ง 2;
     ...;
}
else
{
    คำสั่ง 1;
    คำสั่ง 2;
     ...;
}

ตัวอย่าง Flowchart การทำงาน



ตัวอย่าง source code จาก flowchart
#include  <stdio.h>
#include  <conio.h>
#include  <graphics.h>
void main()
{
     clrscr();
     char ch;
     printf("Press 'c' to draw circle other to draw line :");
     ch=getch();
     int gdriver = DETECT, gmode, errorcode;
     initgraph(&gdriver, &gmode, "c:/tc/bgi/");
     if (ch=='c')
     {
         circle(100,200,50);
         circle(200,200,50);
         circle(300,200,50);
     }
     else
     {
         line(200,200,300,100);
         line(300,100,400,300);
         line(400,200,500,100);
     }
     getch();
     closegraph();
}

กลับหน้าหลัก |