Answer to Question #215838 in C++ for himanshu kumar

Question #215838

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.


1
Expert's answer
2021-07-11T14:35:15-0400
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS