how can i write a program which will find the square root of a number?
Printable View
how can i write a program which will find the square root of a number?
Well generally you'd use the ^ symbol to square things but I don't think you can in C++, so I'd probably do:
Also, I think there would already be functions to do this, probably in the math.h header or something. You might want to look that up.Code:int Square(int Number)
{
return Number * Number;
}
That of course would square the number, not provide the square root of the number.
LOL Sorry! It's a bit late over here.
That should read
return Number / Number;
Rather than
return Number * Number;
Number / Number is 1 unless Number is 0 in which case it's undefined.Quote:
return Number / Number;
To get the square root of a number you can use the sqrt function in <cmath>Code:#include <cmath>
#include <iostream>
using namespace std;
int main()
{
double n = 9.0;
cout << "sqrt(" << n << ") = " << sqrt(n) <<'\n';
}
Okay, I just lost all credibility on this forum.:rolleyes:
Better go and make a new identity.
And since I dont have <cmath>, what do I do?
Try <math.h>. Oh, you don't have that either? :D
nah i have that