sqrt
#include <bits/stdc++.h> using namespace std; int main() { int x; cout << "x = "; cin >> x; cout << "sqrt(x) = " << sqrt(x); cout << endl; cout << "sqrt(x) = " << (int)sqrt(x); cout << endl; printf("sqrt(x) = %d", sqrt(x)); cout << endl; printf("sqrt(x) = %lf", sqrt(x)); return 0; }
测试样例
sqrt只能作用于正整数,默认返回值是double类型。