Answer to Question #230067 in C++ for Arup

Question #230067

WAP in c++ to find any integer power of a integer number(both numbers are user i/p)[using class and object]


1
Expert's answer
2021-08-26T23:46:46-0400
#include <iostream>
using namespace std;
class Power{
    int n, exp;
    public:
    Power(){
        cout<<"Input first integer: ";
        cin>>n;
        cout<<"Input second integer: ";
        cin>>exp;
    }
    int pow(){
        if(n == 0) return 0;
        if(n == 1) return 1;
        if(exp == 0) return 1;
        int res = 1;
        while(exp > 0){
            res *= n;
            exp--;
        }
        return res;
    }
};
int main(){
    Power p;
    cout<<p.pow();
    return 0;
}

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