Programming assingment

Closed
ayigbe Posts 1 Registration date Tuesday November 20, 2012 Status Member Last seen November 20, 2012 - Nov 20, 2012 at 05:24 AM
Zohaib R Posts 2368 Registration date Sunday September 23, 2012 Status Member Last seen December 13, 2018 - Nov 20, 2012 at 08:06 AM
Hello,

How do i write a program in c++ to calculate the square root of a number?

Thanks
Related:

1 response

Zohaib R Posts 2368 Registration date Sunday September 23, 2012 Status Member Last seen December 13, 2018 69
Nov 20, 2012 at 08:06 AM
Hi ayigbe,

You can check the below mentioned code to write the program to calculate square root of a number in C++.

#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
double number; //user input
double answer; //answer to square root
cout << "Please enter a number: ";
cin >> number; //get the user input
cout << endl << endl;
answer = sqrt(number);
cout << "The square root of " << number;
cout << " is " << setprecision(4) << answer << endl;
return(0);
}

Do reply with results.
0