Demonstrate sqrt() function from cmath - C++ Function

C++ examples for Function:Math Function

Description

Demonstrate sqrt() function from cmath

Demo Code

#include <iostream>
#include <cmath>
using namespace std;
int main()/*from  ww w  .jav  a  2  s .  co  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;
}

Result


Related Tutorials