/ Published in: C++
Recursive function to get the power of ten without cmath
Expand |
Embed | Plain Text
int main(){ int ten = 10; int shrink = 2; 1027 = 4;//or customize numLENGTH function below to get length? length = 4; powerOF(ten,shrink,length); } int powerOF(int& ten, int& shrink, int& length){ if(length != shrink){ ten = (ten * 10); length--; powerOF(ten,shrink,length); } return ten; } void numLENGTH(int& num,int& length){ if(num != 0){ num = num/10; length++; numLENGTH(num,length); } }
You need to login to post a comment.
