Find largest numbers

This is a discussion on Find largest numbers within the C Programming forums, part of the General Programming Boards category; Hello. I have question. For example i have a structure with items in shop. I want to find out which ...

  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 08:42 AM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,687
    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 09:58 AM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

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, 10:21 PM
  5. how do u find 2nd largest number??
    By juancardenas in forum C Programming
    Replies: 8
    Last Post: 02-14-2003, 07:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21