Question about one dimensional array

This is a discussion on Question about one dimensional array within the C++ Programming forums, part of the General Programming Boards category; how can i get the largest and smallest value that i input if i input 10 integers? thank you...new in ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    Question about one dimensional array

    how can i get the largest and smallest value that i input if i input 10 integers?

    thank you...new in programming

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    If you had a deck of cards that you could only go through one by one, a piece of paper, and a pencil, how would you do the same task?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    As recommended, what would you do? If someone asks you: how much money would you want from this list: $1, $0, $100, $50, $1000, $42, how do you determine your answer? Do you just look at the first one? Just the last one? Just the, say, middle one? Do you look at all of them?

    For any general list (or array), there is only one solution. KISS.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nadroj View Post
    For any general list (or array), there is only one solution. KISS.
    This should apply to ALL programming tasks.

    Anyway, use a for loop and a variable of the same type as the array set to the lowest possible value, then compare and update that variable, if appropriate, in the loop.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by MK27 View Post
    This should apply to ALL programming tasks.
    What part? Having a single, unique solution to all general programming tasks? Or the "KISS" principle? I just mentioned "KISS" to him/her because I imagine he/she is just starting out with this sort of thing, and we often tend to overthink or overcomplicate things when starting to learn them. It was my way of saying "dont think too hard about this problem, as you will see when you get it it is a simple solution."

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    The KISS principle.

    I guess that implies there often really is one "best" solution (the simplest one). I just think it's a great principle that's worth keeping in mind esp. when programming. Of course, what simple means is ambiguous -- maybe a combination of efficiency and productivity. "Productivity" takes into account that what is simple to one person can be impossible to another. Since you are unlikely to forget who you are, that makes KISS pretty simple to apply most of the time.
    Last edited by MK27; 03-01-2010 at 02:11 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Embaracing Array question
    By DavidDobson in forum C Programming
    Replies: 2
    Last Post: 04-06-2009, 10:29 AM
  2. Multi dimensional array
    By $l4xklynx in forum C Programming
    Replies: 7
    Last Post: 01-03-2009, 02:56 AM
  3. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 06:07 PM
  4. two dimensional string array question
    By Hoser83 in forum C Programming
    Replies: 8
    Last Post: 02-07-2006, 07:15 PM
  5. Array of Structs question
    By WaterNut in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2004, 02:58 PM

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