We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,787 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Counting Integers Algorithm

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

3
Contributors
3
Replies
5 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
Matth963
Light Poster
25 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

JamesCherrill
... trying to help
Moderator
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

Thanks a lot!

Matth963
Light Poster
25 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
Skill Endorsements: 1
Question Answered as of 1 Year Ago by JamesCherrill and hfx642

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0911 seconds using 2.66MB