Thread: Function without Array

  1. #1
    Registered User
    Join Date
    Nov 2001

    Question Function without Array

    IM new programming and IM writing a program in C that reads
    in floating point numbers until the user terminates the program by entering a certain value. The program then needs to find the largest, smallest, and average of all the numbers entered. My problem is IM not allowed to use an array to solve the problem. IM writing functions for each of the three criteria, smallest, largest etc. Can his be done?

  2. #2
    Registered User
    Join Date
    Aug 2001
    For each function, compare the number against a previously stored value (initializing to the first number passed in). That way, you start out with the first number input as the largest, smallest, and average.

    For the largest/smallest functions, just keep track of the appropriate value. For the average, just keep adding the values using a += assignment, while keeping track of the number of time the function was called. Then divide the total by the number of times the function was called, and return the result.

    Hope this helps.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Passing my array to function
    By pooty tang in forum C Programming
    Replies: 8
    Last Post: 09-15-2004, 12:19 PM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM
  5. Replies: 3
    Last Post: 03-23-2002, 04:20 PM