Upgrade to Pro — share decks privately, control downloads, hide ads and more …

if else statement

Nedval
October 18, 2016
49

if else statement

Nedval

October 18, 2016
Tweet

Transcript

  1. if 條件陳述中常用的運算子 邏輯 && 而且 || 或者 == 等於 !=

    不等於 <= 小於等於 >= 大於等於 < 小於 > 大於
  2. if 條件陳述中常用的運算子 邏輯 && 而且 || 或者 == 等於 !=

    不等於 <= 小於等於 >= 大於等於 < 小於 > 大於 個人偏好在程式中 只使用 <= 和 < 不使用 >= 和 > 因為寫起來的順序 與數線相同 較容易閱讀
  3. int temperature; printf("請輸入現在溫度(°C): "); scanf("%d", &temperature); if (26 < temperature

    ) { printf("可以開冷氣"); } else { printf("不能開冷氣"); }
  4. //宣告一個名字為 temperature 的空間用來存放溫度的值 int temperature; //提示使用者輸入溫度 printf("請輸入現在溫度(°C): "); //讀取使用者輸入的溫度並存放到 temperature

    的空間 scanf(“%d”, &temperature); if (26 < temperature ) { // 若溫度大於 26 度則顯示可以開冷氣 printf(“可以開冷氣”); } else { // 若溫度沒有大於 26 度則顯示不能開冷氣 printf("不能開冷氣"); }