printing the max number

This is a discussion on printing the max number within the C Programming forums, part of the General Programming Boards category; Hello I have a array with 4 numbers, I can't figure out how I can find and print the maximum ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    48

    printing the max number

    Hello

    I have a array with 4 numbers, I can't figure out how I can find and print the maximum number in the array. What is the best way of doing this?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,127
    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    48
    I can't figure it out

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,127
    Really?

    Consider this list of four integers by systematically reading them from one direction, e.g., left to right:
    2 4 6 2

    What is the maximum number? How did you know it was the maximum?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    Code:
    for(i=0; i<4; i++){
    		if(array[i]>maxvalue)
    			maxvalue = array[i];
    This sounds like homework, so make sure you understand it.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,127
    osxd00d, read our homework policy.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    48
    Thanks, now that I see it it looks so simple

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by arya6000 View Post
    Thanks, now that I see it it looks so simple
    Yeah, getting your homework done by someone else is rather simple.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    16
    Quote Originally Posted by arya6000 View Post
    Thanks, now that I see it it looks so simple
    Well, it is, but when you have someone else do your hw for you, it's going to catch up with you.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,901
    Basically, find the highest number (how would you do it in reality of you had a bunch of numbers to look at?), then print out that number when you find it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Number Guessing
    By blacknapalm in forum C Programming
    Replies: 2
    Last Post: 10-01-2008, 02:48 AM
  3. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 10:53 PM
  4. printing a number that starts with 0
    By Max in forum C Programming
    Replies: 2
    Last Post: 11-13-2002, 09:01 AM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM

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