C++ sqrt()
#include <iostream> #include <cmath> using namespace std; int main()//w w w. j ava 2 s . c o m { double number, answer; //sqrt() requires type double cout << "Enter a number: "; cin >> number; //get the number answer = sqrt(number); //find square root cout << "Square root is " << answer << endl; //display it return 0; }
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main()//from w w w . j a va 2s . co m { const int MAXCOUNT = 5; int count; cout << "NUMBER SQUARE ROOT\n"; cout << "------ -----------\n"; cout << setiosflags(ios::showpoint); for (count = 1; count <= MAXCOUNT; count++) cout << setw(4) << count << setw(15) << sqrt(double(count)) << endl; return 0; }