Thread: Find largest numbers

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    58

    Find largest numbers

    Hello. I have question. For example i have a structure with items in shop. I want to find out which items i have most. This code words but finds only one item, but if i have several items with same quantity the output still one item. The question is how to make program to show all Items with same biggest quantity.
    Code:
           for (k=1;k<i;k++)
           {
               if (item[k].quantity>=item[k-1].quantity)
               max=k;
               }
               printf ("most items \n");
               printf (" %s %d \n ",item[max].name,item[max].quantity);
               system("pause");   
    }
    Last edited by krakatao; 02-04-2012 at 09:42 AM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    First pass find the largest
    Second pass print out all that equal the largest found in pass one.

    Tim S.
    Last edited by stahta01; 02-04-2012 at 10:58 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To Find Largest Consecutive Sum Of Numbers In 1D Array
    By chottachatri in forum C Programming
    Replies: 22
    Last Post: 07-10-2011, 01:43 PM
  2. Find last largest integer in array?
    By schmidtc in forum C Programming
    Replies: 2
    Last Post: 07-05-2010, 01:00 PM
  3. Find the Largest and Smallest Number
    By Nightsky in forum C Programming
    Replies: 27
    Last Post: 09-04-2006, 03:40 PM
  4. Find largest and second largest number (help)
    By Arkon in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2006, 11:21 PM
  5. how do u find 2nd largest number??
    By juancardenas in forum C Programming
    Replies: 8
    Last Post: 02-14-2003, 08:28 AM