PuyZi

วันจันทร์ที่ 11 กรกฎาคม พ.ศ. 2554

โปรเเกรมภาษา c

Chapter 3 Chapter 3
C Language Control C Language Control

Contents
  • Decision / Selection
  • Loop / Repetition
  • Break and Continue Statement
DECISION / SELECTION
Decision / Selection
  • if then
  • if then else
  • Nested if
  • switch switch
if then
            Format:
            if (expression)
            statement;

if then
           Format:
           if (expression) {
           statement-1;
           statement-2; statement-2;
          …
}


Example if1.
#include <stdio.h>
#include <stdlib.h>
int main( ) {
     int  i;
     scanf(“%d”, &i);
if (i > 0)
     printf(“a positive number was entered\n”);
system(“PAUSE”);
return 0;

}

Example if2.c
#include <stdio.h>
#include <stdlib.h>
int main( ) {
    int  i;
    scanf(“%d”, &i);
    if (i < 0) {
          printf(“a negative number was
          i = -i;
    }
   system(“PAUSE”);
   return 0;
}

printf(“a positive number w
system(“PAUSE”);
return 0;
}


if then else
Format:  if (expression)
      statement-true;
else else
      statement-false;

if then else
Format:
if (expression) {
   statement-1;
   statement-2;
   …
} else {
   statement-3;
   statement-4;

}

ป้ายกำกับ:

0 ความคิดเห็น:

แสดงความคิดเห็น

สมัครสมาชิก ส่งความคิดเห็น [Atom]

<< หน้าแรก