I am new to C prog. and I was wondering how to find average of numbers that a user enters.
Thanks for help.
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. ...
I am new to C prog. and I was wondering how to find average of numbers that a user enters.
Thanks for help.
Take the sum and divide by the number of numbers. What have you tried?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i just did that, but i was wondering if there is an average command, or if that is the only way to do average.
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
so there is no way to calculate average??? with a command.....
"Function", not "command". You can write your own function, if necessary.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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 averageCode: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