Question

Write a code segment (block) using C++ to calculate the average of 10 numbers provided by...

Write a code segment (block) using C++ to calculate the average of 10 numbers provided by the user

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

First, 10 numbers are taken input from the user and added to the sum variable one by one.

Then, average is calculated by dividing the sum by 10.

Here is the code with comments to explain the working.

Code Segment:


#include <iostream>

using namespace std;

int main()
{
int sum=0; //Sum variable to keep adding the numbers given by the user
cout<<"Enter 10 numbers: "<<endl;
for(int i=0; i<10; i++) //Loop to take input 10 numbers and adding them to sum one by one.
{
int n;
cin>>n;
sum = sum +n;
}
  
float avg = (float)sum/(float)10; //Calculating and storing average of numbers using sum of numbers.
  
cout<<"Average is: "<<avg<<endl; //Printing the average of numbers.

return 0;
}

#include <iostream> using namespace std; int main() int sum=0; cout<<Enter 10 numbers: <<endl; for(int i=0; i<10; i++) int

Output:

Enter 10 numbers: Average is: 25.5 ...Program finished with exit code 0 press ENTER to exit console. I

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

please comment if you have any doubts!

Add a comment
Know the answer?
Add Answer to:
Write a code segment (block) using C++ to calculate the average of 10 numbers provided by...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a code segment to calculate the total product of 15 numbers provided by the user....

    Write a code segment to calculate the total product of 15 numbers provided by the user. Code block for programming

  • write a code segment for a loop to calculate the sum of first 10 odd numbers...

    write a code segment for a loop to calculate the sum of first 10 odd numbers [what your program computes is 1+3+5+7+9+11+13+15+17+19. store the result in register r0.] it’s assembly language

  • Using Python The variables x and y refer to numbers. Write a code segment that prompts...

    Using Python The variables x and y refer to numbers. Write a code segment that prompts the user for an arithmetic operator and prints the value obtained by applying that operator to x and y. Using the following information run an example in Python Idle op = input("Enter an arithmetic operator: ") if op == "+":     print(x + y) elif op == "-":     print(x – y) elif op == "*":     print(x * y) elif op == "/":...

  • Write a C++ segment of code in main () that reads a file called "numbers txt"....

    Write a C++ segment of code in main () that reads a file called "numbers txt". You should cout the range of the numbers in the file, for example if the file contained "3.5 1.8 15" the range of numbers is 15 - 1.8 = 13.2.

  • Write pseudo code that will read in 3 numbers that a user enters, pass them to...

    Write pseudo code that will read in 3 numbers that a user enters, pass them to a module that will calculate the average of the 3 numbers and display them OR Write pseudo code that will read in 3 numbers that a user enters, pass them to a function that will calculate the average of the 3 numbers and return it to the main module. Display the average in the main module.

  • Write a program in C++ to calculate the average (mean) and the standard deviation of a...

    Write a program in C++ to calculate the average (mean) and the standard deviation of a list of numbers using vectors. Your program should... Prompt for the number of values the user wishes to enter Prompt the user to enter the values one at a time for the number of requested values into a vector Calculate and display the Mean and Standard Deviation The flow of your code should be similar to: int main() { /** Prompt the user and...

  • use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers...

    use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...

  • (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers...

    (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers entered by the user:  Ask the user to enter an integer number or -1 to stop  Add the entered numbers  Compute the average of the numbers outside the loop after termination  Print the average

  • Please use C programming to write a code segment as an answer. Instead of using an...

    Please use C programming to write a code segment as an answer. Instead of using an while-loop like the following code, please implement a code segment by using a do-while loop. What is the output of the code? #include <stdio.h> void main() {        int i = 0;        while (i < 5);        {               printf(“%d ”, ++i);        } }

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT