--- tags: DICE C --- 3-4 身高與體重 === > [name=CHAWTeam] [time=Feb 15, 2022] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[3-3 指定浮點數](https://hackmd.io/@CHAWTeam/DiceC-3-3) 下一篇:[3-5 =不是等號](https://hackmd.io/@CHAWTeam/DiceC-3-5) --- 題目 --- ```! 寫一個程式,指定一個整數為160,一個浮點數為55.22,分別代表身高與體重,並印出其值,格式如輸出範例所示。 輸出範例: My height is 160 CM. My weight is 55.22 KG. ``` 程式碼 --- ### 範例1 ```c= #include <stdio.h> int main() { int num1 = 160; float num2 = 55.22; printf("My height is %d CM.\n", num1); printf("My weight is %.2f KG.", num2); //「%.2f」取小數到第二位 return 0; } ``` ### 範例2 ```c= #include <stdio.h> int main() { int num1 = 160; float num2 = 55.22; printf("My height is %d CM.\nMy weight is %.2f KG.", num1, num2); //「%.2f」取小數到第二位 return 0; } ``` :::success 記得加上`,`分隔不同的變數喔! ::: :::info 「%.1f」取小數到第一位 「%.2f」取小數到第二位 以此類推…… ::: 輸出 --- ```! My height is 160 CM. My weight is 55.22 KG. ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[3-3 指定浮點數](https://hackmd.io/@CHAWTeam/DiceC-3-3) 下一篇:[3-5 =不是等號](https://hackmd.io/@CHAWTeam/DiceC-3-5) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-3-4" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up