Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.
using namespace std;
int main()
{
int a, b, c, x;
cout<<"Enter the value of a: "<<endl;
cin>>a;
cout<<"Enter the value of b: "<<endl;
cin>>b;
//second method using <math.h>
//c = pow(a,b);
c = 1;
x = b;
while(b!=0)
{
c = c * a;
b = b - 1;
}
cout<<a<<" raised to the power "<<x<<" is "<<c<<endl;
}
Comments
Leave a comment