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

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

int score;

printf("阿呆,你考幾分?");
scanf("%i", &score);


switch(score){
//自訂區域 case(空格)90...(空格)100  表示 90~100
case 90 ... 100:
printf("level A");
break;
case 80 ... 89:
printf("level B");
break;
case 70 ... 79:
printf("level C");
break;
case 60 ... 69:
printf("level D");
break;
case 0 ... 59:
printf("不及格唷");
break;
default :
printf("亂來!!亂輸入!!");
break;

//     可以寫成區域,程式進入方法的括號會配置記憶體,離開括號後會釋放記憶體
// case xxx:{
//    int abc;
// }break;

}




return 0;
}


kenohya 發表在 痞客邦 留言(0) 人氣()

#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;
}


kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

int userinput;

//共取一個亂數庫,否則遊戲會失去平衡機制
srand(time(NULL));
//rand()產生 0~32767 其中一個數字
int answer = rand()%9+1;  //1~9亂數產生



printf("輸入1~9其中一個數字");
//旗標重始點,當看到以下程式 goto flag時候,會再回到flag處執行,goto不適合開發用,            因為可能會早成無窮迴圈
flag:
scanf("%i", &userinput);



if(userinput == answer){
      printf("輸入正確!好棒唷!");
}else if (userinput >=1 && userinput<=9){
printf("輸入錯誤!請重新輸入");
}else{

printf("超出1~9啦!");
goto flag;

}

printf("開獎號碼為%i", answer);


return 0;

}


kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

int num1, num2, num3;
int max;

printf("輸入三個數字比大小");
scanf("%i%i%i", &num1, &num2, &num3);


//      第一種直覺的想法

// if(num1>num2 && num1>num3){
// max =num1;    //num1不是最大,迴圈就不用管num1,num1剃除
// }else if(num2>num3){
// max = num2;   //num2不是最大,num2剔除
// }else{
// max = num3;   //num3最大
// }




//第二種淘汰制的想法

if(num1>num2){   //num2被淘汰,剩下num1和num3比
if(num1>num3)
max = num1;
else
max = num3;
}else{
if(num2>num3)
max = num2;
else
max = num3;
}


//最後印出max
printf("%i最大", max);

return 0;
}


kenohya 發表在 痞客邦 留言(0) 人氣()

#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;
}


kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

//條件判斷式 if else, while, ...

int input;

printf("請輸入一個整數:");
scanf("%i", &input);



// input 除以2,餘數等於0,就是偶數
// 當然啦,如果input初以2於1的話,就是奇數

if(input%2==0){
printf("您輸入的值%i是偶數", input);
}else{
printf("您輸入的值%i是奇數", input);
}



//也可以寫成這樣,因為 if(input%2) = if(1)

if(input%2){
printf("您輸入的值%i是奇數", input);
}else{
printf("您輸入的值%i是偶數", input);
}



//也可以寫成這樣,用!作反向
if(!(input%2)){
printf("您輸入的值%i是偶數", input);
}else{
printf("您輸入的值%i是奇數", input);
}

return 0;

}


kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

int a=1, b=2, c=3;

//a < b --> output=0 表示 錯誤
//a < b --> output=1 表示 正確
printf( " %i < %i ? %i \n " , a, b, a<b );  // 1 
printf( " %i < %i ? %i \n" , a, b, a>=b);  // 0



return 0;
}


kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

//華氏溫度
int Fah;
        //攝氏溫度
float Cel;


printf("input Fah:");

scanf("%i", &Fah);

//C++內的5.0是指5.0d,C內的5.0指5.0f
Cel = (Fah - 32)*(5.0f / 9);

printf("Cel is %.2f ", Cel);

return 0;
}


kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

int price;
float discounts, total;

printf("老闆請問多少錢?\n");


 //取記憶體price的數值
scanf("%i", &price);

printf("老闆請問打幾折?\n");
scanf("%f", &discounts);

 //算出total價格
total = price*discounts/10;

//取小數點後2位
printf("打 %.2f 折後為%f", discounts, total);

return 0;
}

kenohya 發表在 痞客邦 留言(0) 人氣()

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

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

int enter;

//請求輸入-->轉譯 -->放入記憶體位置
printf("input:\n");

//記憶體取 &enter值,丟到 %i
//&是取得記憶體空間的意思
scanf("%i", &enter);


//印出輸入的值
printf("your input is :%i\n",enter);

       //0表示關閉程式
return 0;
}


kenohya 發表在 痞客邦 留言(0) 人氣()