Programming assingment

[Closed]
Report
Posts
1
Registration date
Tuesday November 20, 2012
Status
Member
Last seen
November 20, 2012
-
Posts
2368
Registration date
Sunday September 23, 2012
Status
Member
Last seen
December 13, 2018
-
Hello,

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

Thanks

1 reply

Posts
2368
Registration date
Sunday September 23, 2012
Status
Member
Last seen
December 13, 2018
44
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.