/* t2_1.c ( PASCAL講座 sample program ) if 文、switch 文、goto 文 コンパイル命令は gcc t2_1.c -o t2_1 実行命令は t2_1 */ #include #include main() { int a,b; char c; the_label: a=rand()%3; /* 0,1,2 の整数乱数を発生 */ b=rand()%3; printf("a = %1d\n",a); printf("b = %1d\n",b); if(a==b) printf("a is equal to b\n"); else printf("a is not equal to b\n"); printf("\n"); switch(a){ case 0: printf("Hello.\n"); break; case 1: printf("How are you.\n"); break; case 2: printf("Nice to meet you.\n"); } printf("\n"); printf("----- Hit 0 to stop -----\n"); c=getchar(); if(c!='0') goto the_label; }