開啟章節選單
sqrt
概念講解
首先宣告一個整數變數 n
並輸入:
int n; cin >> n;
最後,在輸出答案前,要先調整小數點的位數,這邊要加上 fixed << setprecision(2)
來調整小數點的位數,而開根號的函式是 sqrt()
cout << fixed << setprecision(2) << sqrt(n);
範例程式碼
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << fixed << setprecision(2) << sqrt(n); }