WAP in c++ to find any integer power of a integer number(both numbers are user i/p)[using class and object]
#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;
}
Comments
Leave a comment