Posted By

trentonknight on 10/05/10


Tagged

10 power of


Versions (?)

Power of Ten


 / Published in: C++
 

Recursive function to get the power of ten without cmath

  1. int main(){
  2.  
  3.  
  4. int ten = 10;
  5. int shrink = 2;
  6.  
  7. 1027 = 4;//or customize numLENGTH function below to get length?
  8. length = 4;
  9.  
  10. powerOF(ten,shrink,length);
  11. }
  12.  
  13. int powerOF(int& ten, int& shrink, int& length){
  14. if(length != shrink){
  15. ten = (ten * 10);
  16. length--;
  17. powerOF(ten,shrink,length);
  18. }
  19. return ten;
  20. }
  21. void numLENGTH(int& num,int& length){
  22.  
  23. if(num != 0){
  24. num = num/10;
  25. length++;
  26. numLENGTH(num,length);
  27. }
  28. }

Report this snippet  

You need to login to post a comment.