#學習 C=> 浮點數和變量
## 浮點數
到了浮點數這一類型,之前的整數類型有int聲明變量,現在有float來聲明
他的用處主要是可以存儲帶小數的數字,而printf打印他的話需要用"%f"來處理浮點值,而這個exmple.c中的%.2f是用於精確輸出,顯示小數點後兩位
###scanf()
另外用到了scanf()函數,讀取鍵盤的輸入
#include <stdio.h>
int main(void) {
float weight; // weight
float value; // gold
printf("Are you worth your weight in platinum?\n");
printf("Let's check it out.\n");
printf("Please enter your weight in pounds: ");
// uses output
scanf("%f", &weight);
value = 1700.0 * weight * 14.5833;
printf("Your weight in platinum is worth $%.2f.\n", value);
printf("You are easily worth that! If platinum prices drop,\n");
printf("eat more to maintain yor value.\n");
getchar();
getchar();
return 0;
}
(應該不會有什麼問題吧 ^^)
此文由 Mix Space 同步更新至 xLog
原始鏈接為 https://www.xingbest.fun/posts/programming/C-Study(1)