Thread: arrays

  1. #1
    Unregistered
    Guest

    Question arrays

    Hey all!!

    i've tried every possible combo for outputing arrays lowest umber to highest number and i'm stumped..can anyone out there give me the basic format..how many for loops ..ect? really stumped here, would appreciate any help
    thanks

  2. #2
    Unregistered
    Guest

    Cool

    i guess i should be a little more specif, i have to compare to arrays, but to do that i need to put them both in numerical order, lowest to highest or vive versa, the comparing i have no probs with, its just the dang arranging lol.. oh well thanks again if anyone gets a chance to reply

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    This sorts the array with the largest number first:
    Code:
    int i,j,temp;
    
    //Loop through every number except the last
    for(i=0; i<(NrOfElements-1); i++)
    {
      //Loop through every number after i
      for(j=(i+1); j<NrOfElements; j++)
      {
        //If a higher number is located after a lower, switch
        if(Array[i]<Array[j])
        {
          //Switch the values
          Temp=Array[i];
          Array[i]=Array[j];
          Array[j]=Temp;
        }
      }
    }
    Last edited by Magos; 03-31-2002 at 12:54 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Unregistered
    Guest

    Talking

    many thanks my lord, your help is invaluble

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    No problem, that's what this forum is for
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    just call him lord of the protoss

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by frenchfry164
    just call him lord of the protoss
    Preator perhaps...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM