Average

This is a discussion on Average within the C Programming forums, part of the General Programming Boards category; I am new to C prog. and I was wondering how to find average of numbers that a user enters. ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Average

    I am new to C prog. and I was wondering how to find average of numbers that a user enters.
    Thanks for help.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,935
    Take the sum and divide by the number of numbers. 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
    Jan 2008
    Posts
    3

    avegare

    i just did that, but i was wondering if there is an average command, or if that is the only way to do average.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,935
    To the best of my knowledge, there is no function in the C standard library for computing an arithmetic mean. There are probably other ways to calculate the mean when say, a sum is too large to be stored in the variable, but I am not certain about such methods. And, of course, the mean is just one way to take the average, the median and mode being two other ways.
    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
    Jan 2008
    Posts
    3
    so there is no way to calculate average??? with a command.....

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,935
    "Function", not "command". You can write your own function, if necessary.
    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 2006
    Location
    Canada
    Posts
    1,243
    if you are very new to C and procedural programming, your best bet is to read the tutorials on the main cprogramming.com site.

    once getting a basic introduction to a c programs structure, console input and output, functions, primitive data types (for example int and char) then you might be able to translate the following pseudo code into a c program. for simplicity, the function will take in 3 numbers (integers) and print the average
    Code:
    function printAverage(int number1, int number2, int number3)
       define sum as integer
       set sum = 0
       define average as floating point value (ie real number)
       set average = 0
    
       set sum = sum + number1
       set sum = sum + number2
       set sum = sum + number3
    
       set average = sum / 3
    
       print average

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Average score
    By wiz23 in forum C++ Programming
    Replies: 22
    Last Post: 05-05-2005, 05:38 AM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM

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