We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,534 Members — Technology Publication meets Social Media

# Problem with Count Output

I'm causing input letters to write ones into variables through an array. I'm trying to count the occurences of ones in a variable. Lets say I input aaaaa. The count output displays 12345. Instead of outputting the whole count of numbers, I want to output the biggest number in the count. How can I do that?

3
Contributors
2
Replies
13 Hours
Discussion Span
8 Months Ago
Last Updated
3
Views
quantumss
Newbie Poster
1 post since Sep 2012
Reputation Points: 0
Skill Endorsements: 0

Look for the biggest number.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Skill Endorsements: 37

Here is hint for finding largest number in count.

Extract digits from count and insert them in an array.

Finding largest element in an array.

max = array[0] ;

i = 1;

while ( i <= array length )
{
if( array[i] > max )
{
max = array[i] ;
}

}

How to extract digits from count ?

First do count modulo 10 and take remainder. It gives the last digit.
Then divide count by 10 and store it in an integer so that, the last digit is left out ( This happens because dividing integer by 10 gives a float value with decimal point before last digit ).
Continue the process untill dividing by 10 gives answer 0.

Hope this helps.

np complete
Posting Whiz
385 posts since Sep 2010
Reputation Points: 18