Quick Q: How to square numbers???

So I tried "square()" with no luck. My compiler (Dev-C++) spit it back at me like a nasty biscuit. Any ideas?

-Incline
Last edited on
Have you tried?
1
2
3
 
#include <cmath>
pow(a,b);

Last edited on
You can use the pow and sqrt in cmath
to find the power or square root of a number.


pow: http://www.cplusplus.com/reference/cmath/pow/
sqrt : http://www.cplusplus.com/reference/cmath/sqrt/
cmath: http://www.cplusplus.com/reference/cmath/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
#include<cmath>

using namespace std;

int main(){
float base = 5.0;
float power = 2.0;
float square = pow(base,power);
float squareroot = sqrt(square);

cout << base << " to the " <<  power << " power is: " << square << endl;
cout << "the square root of " << square << " is " << squareroot << endl;

}
Thank you both.
Topic archived. No new replies allowed.