--- tags: DICE C --- 3-3 指定浮點數 === > [name=CHAWTeam] [time=Feb 15, 2022] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[3-2 加上一些形容詞](https://hackmd.io/@CHAWTeam/DiceC-3-2) 下一篇:[3-4 整數與浮點數](https://hackmd.io/@CHAWTeam/DiceC-3-4) --- 題目 --- ```! 寫一個程式,指定二個浮點數為10.100000與5.200000,並且印出結果,格式如輸出範例所示。 輸出範例: 10.100000 5.200000 C++程式範例: #include<iostream> #include<iomanip> using namespace std; int main() { float num1,num2; num1=10.100000; num2=5.200000; cout<<fixed<<setprecision(6)<<num1<<endl; cout<<fixed<<setprecision(6)<<num2<<endl; return 0; } ``` 程式碼 --- ### 範例1 ```c= #include <stdio.h> int main() { float num1 = 10.1; //定義浮點數 num1 為 10.1 float num2 = 5.2; //定義浮點數 num2 為 5.2 printf("%f\n", num1); //「%f」為小數格式指定字 printf("%f\n", num2); return 0; } ``` ### 範例2 ```c= #include <stdio.h> int main() { float num1 = 10.1, num2 = 5.2; //也可以並排定義多個變數 printf("%f\n", num1); //「%f」為小數格式指定字 printf("%f\n", num2); return 0; } ``` 輸出 --- ```! num1=10.100000 num2=5.200000 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) 上一篇:[3-2 加上一些形容詞](https://hackmd.io/@CHAWTeam/DiceC-3-2) 下一篇:[3-4 整數與浮點數](https://hackmd.io/@CHAWTeam/DiceC-3-4) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-3-3" 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