switch_case.c
/*------------------------------------------------------------------------------
* Title: switch_case
* Project: switch_case
* Source: switch_case.c
* Author: B.G
* Group: B.G
* Created: 0:36 2009/11/11
* Last Modified: 0:36 2009/11/11
* ---------------------------------------------------------------------------*/
/* ヘッダファイルのインクルード */
#include <stdio.h> /* stdio.hのインクルード */
/* main関数 */
int main(void){
/* 変数の宣言 */
int no; /* 入力された値を格納するint型変数no */
/* 入力された値をnoに格納する */
printf("no:"); /* noの入力 */
scanf("%d", &no); /* scanfで入力値をnoに格納 */
/* switch-case文で判断 */
switch (no){ /* noの値をチェックする */
case 0: /* no = 0のとき */
printf("no = 0\n"); /* "no = 0"と表示 */
break; /* ここで終了させるため必ずつける */
case 1: /* no = 1のとき */
printf("no = 1\n"); /* "no = 1"と表示 */
break; /* ここで終了させるため必ずつける */
case 2: /* no = 2のとき */
printf("no = 2\n"); /* "no = 2"と表示 */
break; /* ここで終了させるため必ずつける */
case 3: /* no = 3のとき */
printf("no = 3\n"); /* "no = 3"と表示 */
break; /* ここで終了させるため必ずつける */
default: /* 上記のどれにも当てはまらないとき */
printf("no >= 4\n"); /* "no >= 4"と表示 */
}
/* プログラムの終了 */
return 0;
}
最終更新:2010年07月08日 14:09