1.11M Members

Counting Integers Algorithm

 
0
 
int numdigits(int num){

int len = 0;

while(num >= 10){
num = num/10;
len++;
}

return len;
}

This algorithm is used to count the number of digits but I can't understand it.
Someone explain it to me please :D

Thanks

 
1
 

Add print statements after each line to print out the values that were set/changed on that line. Then you'll be able to understand how it works.

 
0
 

Thanks a lot!

 
0
 

Well... It works, but it will be 1 digit short.

Question Answered as of 2 Years Ago by JamesCherrill and hfx642
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: