Is there a way to find the square of a number (e.g. x^2) instead of having to write y=x*x?

Printable View

- 11-13-2002abregesquares
Is there a way to find the square of a number (e.g. x^2) instead of having to write y=x*x?

- 11-13-2002skipper
Research pow() in <math>, i.e.

Code:`z = pow(x, y);`

- 11-13-2002alphaCode:
`#include <iostream>`

#include <cmath> //need for pow() function

int main()

{

int a, b, c;

b = a * a; //I would recommend this method for finding a square

cout << "Enter a base: ";

cin >> a;

cout << "Enter an exponent: ";

cin >> b;

c = pow(a, b); //I would recommend this if raising to uncertain power

return 0;

}

//pow(x, y) is in the form x^y