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
Is there a way to find the square of a number (e.g. x^2) instead of having to write y=x*x?
Research pow() in <math>, i.e.
-SkipperCode:z = pow(x, y);
Code:#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