....

2014年5月15日 星期四

[長知識] C語言 - 新手篇章 - 條件判斷式(switch case )

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {

srand(time(NULL));
int a = rand()%9+1;


//switch case,如果不加上break,程式會一直往下執行
switch(a){
case 1:
printf("頭獎!");
break;
case 2:
printf("二獎!");
break;
case 3:
printf("三獎!");
break;
//除了頭獎、二獎、三獎以外
default:
printf("銘謝惠顧");
break;
}

return 0;
}

沒有留言:

張貼留言