Thread: Searching and Scanning Arrays

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    6

    Searching and Scanning Arrays

    Is there any way to have the program search all the arrays and find the largest entry or smallest entry. Also if you have an array of 20 but only assign 15 places and then enter a sentinal of -1 to have the other places filled by zero

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can just do a simple linear search to find the largest / smallest value in an array. Just simply walk through it and compare the current value to the largest / smallest one currently set.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    And How would one go about doing that. I'm pretty much a novice at c programming.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I'll give you some pseudo code then you make an attempt and coding it and then I can help you again if needed.

    Code:
    integer large = -INT_LIMIT // very small number
    integer i = 0
    
    for each element in our array data ( for loop.. )
      compare current data element with large
      if data element bigger..
        large = data element  
    
      increment i
    That will give you the largest value in your array.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    And How would one go about doing that. I'm pretty much a novice at c programming.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Hah, is there an echo in here?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by apoc632
    And How would one go about doing that. I'm pretty much a novice at c programming.
    One would do that by reading the first chapter of their C book and going from there. We do not do homework for you here. Do what you can, post your attempt, and read the forum rules.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    i got it working thanks. By the way the double post was a mistake.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file scanning?
    By yahn in forum C++ Programming
    Replies: 4
    Last Post: 12-03-2005, 10:27 AM