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

Recommended Answers

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.

Jump to Post

All 3 Replies

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.

Thanks a lot!

Member Avatar

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.