how can i write a program which will find the square root of a number?
This is a discussion on square root within the C++ Programming forums, part of the General Programming Boards category; how can i write a program which will find the square root of a number?...
how can i write a program which will find the square root of a number?
AIM: MarderIII
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; }
Last edited by nickname_changed; 02-12-2003 at 01:00 AM.
That of course would square the number, not provide the square root of the number.
Demonographic rhinology is not the only possible outcome, but why take the chance
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.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'; }
- lmov
Okay, I just lost all credibility on this forum.
Better go and make a new identity.
And since I dont have <cmath>, what do I do?
AIM: MarderIII
Try <math.h>. Oh, you don't have that either?
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
nah i have that
AIM: MarderIII