--- title: 'Project documentation template' disqus: hackmd --- 10/4 {Review} {MORE variables} {Typesetting---「天啊!這怎麼看得懂」} {Relational operator} {If} {Variables-advance application} === ![](https://i.imgur.com/vT7090j.jpg) ![](https://i.imgur.com/o0PytTB.jpg) ## Table of Contents Review Relational operator Typesetting Variables.advance application ### Review 複習上次所學!(゚∀゚) 1. 輸出、輸入ヽ(●´∀`●)ノ **輸出** printf("…"); **輸入** scanf("…"); 2. 輸出、輸入的格式符號(*´艸`*) %d 10進位整數(digit) %f 浮點數(float) %c 字元(char) %s 字串(string) 3.資料型態(,,・ω・,,) ![](https://i.imgur.com/3VH9MMu.png) ### MORE variables!!!!!!!!!!! 1.在生活中的應用ヽ(✿゚▽゚)ノ 在程式語言中的加減乘除 | 運算子 | 代表含意| | ---- | ---- | | + | 加 | | - | 減 | | * | 乘 | | / | 除 | | % | 取餘數 | * 取餘數是什麼@@ ``` #include <stdlib.h> #include <stdio.h> int main() { int a,b; a=1822242; b=91; printf("%d",a%b); return 0; } ``` 執行這段程式碼後的結果是... ![](https://i.imgur.com/DBPZ2FX.png) * 實作~ ``` #include <stdlib.h> #include <stdio.h> int main() { int c,f; printf("請輸入攝氏溫度~"); scanf("%d",&c); f = (c*9/5)+32 printf("經過絲瓜強大的計算,攝氏%d度時,華氏應為%d度",c,f); //華氏 = 攝氏*(9/5)+32 return 0; } ``` 執行後的結果為... ![](https://i.imgur.com/HLyVGS2.png) *換你試試看~* ![](https://i.imgur.com/ft9IVUu.jpg) 把華氏轉成攝氏 **小提示~** 攝氏 = (華氏-32)*5/9 2. How to exchange the value in the variables? 需要多一個變數用來暫時存放其他變數中的值 ``` int a,b,t; a=5; b=6; t=a; a=b; b=t; printf("%d %d",a,b); ``` ### 「天啊!這怎麼看得懂」 論排版的重要性 ![](https://i.imgur.com/6Um7lfI.jpg) ![](https://i.imgur.com/x4ukBeB.png) 衡量樣式及風格品質的標準 – 一致性 • 內縮的必須保持一致! -->中途改變對齊的方式,容易誤導別人,使人以為原始檔案互不相關 • 如果是自訂的個性化樣式規則,應該要保持內部統一 –->括弧的位置也應該要遵循同一規則 ![](https://i.imgur.com/ws2YkgL.png) 優點: • 佔用空間小 • 後括弧與相對應的敘述內縮在同一位置上,所以 容易找到程式的終止點 缺點: • 前後括弧沒有對齊,視覺上不容易匹配 • 如果頁面上的右側少了括弧,很難找出來! • 程式碼一寫多,感覺像是一團麵球! ![](https://i.imgur.com/tndWMxT.png) 優點: • 格式清晰、整潔! • 前後括弧放在很明顯的位置,使得程式碼區塊更容易區分 缺點: • 佔用太多的垂直空間 • 如果有太多程式區塊內只包含一行程式碼,則太佔用空間 **命名方式** • 適當的命名 瞭解名稱就可以瞭解對象 • 加速程式設計師之間的交流 清晰的命名是優秀程式碼的特點之一 • 需要合適命名的對象 變數、函數、型別、C++命名空間和 Java Package、巨集、原始檔案 ### Relational operator 關係運算子 1. 各種常見的關係運算子 | 運算子 | 代表含意| | -------- | -------- | | == | 等於 | | > | 大於 | | < | 小於 | | >= |大於等於| | != | 不等於 | **所!以!** **==和=的差別是甚麼?** a=b 將b的值賦給a,即令a這個變數等於b這個值 a==b 判斷a是否等於b 2. 關係運算子的功用 **判斷** 判斷該數值與其他比較項目的關係,即可利用關係運算子來做判斷 ### If statement 1. IF的語句格式: ``` if(boolean_expression 1) { /* Executes when the boolean expression 1 is true */ } else if( boolean_expression 2) { /* Executes when the boolean expression 2 is true */ } else if( boolean_expression 3) { /* Executes when the boolean expression 3 is true */ } else { /* executes when the none of the above condition is true */ } ``` * In C, any non-zero and non-null values are *true*, and if it's zero or null, it's assumed to be *false*. * An if can have an else or even none, it MUST follow the else if (if there is one). * An if can have 0~many else if, it MUST between if and else . * Once an else if executed successfully, the rest of the else if and else won't be tested. ![](https://i.imgur.com/df21TCA.jpg) 4.實作! [click here~](https://zerojudge.tw/)(或上網搜尋:高中生程式解題系統) 請先註冊-->在上方搜尋欄搜尋題目"a002" 提示如下~ ``` #include <stdio.h> int main() { int a,b; while (scanf("?????", ??? , ???)!=EOF) { printf("?????",???); } return 0; } ``` :::info **Find this document incomplete?** Leave a comment! ::: ###### tags: `Templates` `Documentation`