7

How do I write a C program to enter five numbers and find their sum and average?

 2 years ago
source link: https://www.codeproject.com/Questions/5333240/How-do-I-write-a-C-program-to-enter-five-numbers-a
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

See more:

C program to enter five numbers and find their sum and
average (Do not use array here).

What I have tried:

Unable to write this program without using array function.
Comments
Show your work so far.
If you add the numbers as they are entered it is a simple matter to calculate the average.

Remember what an average is: the sum of the values divided by the number of items.
So the average of 1, 3, 6, 2 is the total (1 + 3 + 6 + 2 = 12) divided by the number of items (4): 12 / 4 = 3

So use a loop. Inside the loop, read a number and add it to a total.
After the loop, divide that total by the number of items (five in your case) and you have both required values.

This isn't a complex task, it's designed to get you thinking about how you convert a requirement into code. So for next time, read this: How to Write Code to Solve a Problem, A Beginner's Guide[^] and think about what you are being asked to do!

Add your solution here

Preview

Existing Members

Sign in to your account

...or Join us

Download, Vote, Comment, Publish.
Your Email  
Password  
 
Your Email  
Optional Password  
StrengthToo short
 
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the CodeProject newsletters
When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK