Find power of without math functions in C++/Cpp
#include<iostream>
using namespace std;
void integerPower(int base, int exp, int &res){
res = 1;
for(int n = 0; exp > n; n ++)
res *= base;
}
int main(){
int expo = 5, res;
for(int base = 2; 5 > base; base ++){
integerPower(base, expo, res);
cout << base << " to power of " << expo << " is " << res << endl;
}
return 0;
}
Download
Comments
Post a Comment