Thread: how do u find 2nd largest number??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    how do u find 2nd largest number??

    i need to find the two largest vaules of 10 numbers using a while loop.

    so far i can only find the largest number but can't fingure out how to get the 2nd largest number.

    here is how i find the largest number

    Code:
    int counter = 1, number, largest = 0, second_largest = 0;
    
    
    while ( counter <= 10 ) {
         printf("enter number: ");
         scanf("%d", &number );
    
           if ( number > largest )
                    number = largest;
         
            counter++;
     }
    how do i find the second largest number???
    Last edited by juancardenas; 02-12-2003 at 11:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code to find th square root of a number
    By CODY21 in forum C++ Programming
    Replies: 34
    Last Post: 10-29-2010, 09:27 AM
  2. finding the largest number in a binary search
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 07-31-2008, 03:19 AM
  3. Find largest and second largest number (help)
    By Arkon in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2006, 11:21 PM
  4. Determining the Largest number??
    By gqchynaboy in forum C++ Programming
    Replies: 4
    Last Post: 08-28-2003, 11:27 PM
  5. Replies: 2
    Last Post: 08-03-2003, 10:01 AM