....

2014年5月15日 星期四

[長知識] C語言 - 新手篇章 - 條件判斷式,年紀判斷

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

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

int age;

printf("請輸入您的年紀:");
scanf("%i", &age);


//巢狀 if
if(age<18 || age>65){
if(age<18){  
//如果只有一行陳述式,可以不用{ }
printf("孩子~請離開本站吧!");
}else{
printf("老人~請離開本站吧!");
}
}else{
printf("歡迎光臨本站!");
}





return 0;
}

沒有留言:

張貼留言