Question

Using C++, create a program to input a list of positive numbers, find the mean (average)...

Using C++, create a program to input a list of positive numbers, find the mean (average) of the numbers, and output the result. Use a subprogram to input the numbers, a function to find the mean, and a subprogram to output the result.

Homework Answers

Answer #1

C++ code:

#include <iostream>
using namespace std;
float Mean(int m[],int n)//function to find mean
{
int s=0;//initializing s which is the sum as 0
for(int i=0;i<n;i++)//looping to find the sum
s+=m[i];//finding sum
return(s/n);//dividing sum by n to obtain mean and returning it
}
int main()//main function
{
cout<<"Enter number of positive numbers: ";//asking user to enter count of numbers
int n;//variable n to store count of numbers
cin>>n;//accpting n
int num[n];//initializing an array to store numbers
for(int i=0;i<n;++i){//loop for accepting values
cin>>num[i];//reading values to num array
}
cout<<"Mean: "<<Mean(num,n)<<endl;//printing mean
return 0;
}

Screenshot of code:

Input and output:

Know the answer?
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
Similar Questions
C++ Write a program that will ask the user to input n positive numbers. The program...
C++ Write a program that will ask the user to input n positive numbers. The program will terminate if one of those number is not positive. please respond quickly and clearly, thank you!
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
write C program using function to read 20 float numbers and print the average of them...
write C program using function to read 20 float numbers and print the average of them after changing the negative to positive number.
PLease code a C++ program that prompts a user to enter 10 numbers. this program should...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the 10 numbers and the average of the 10 numbers please use file i/o and input measures for Handling Errors in C++ When Opening a File
Using NetBeans, create a Java program called Average.java. The program should use the Scanner class to...
Using NetBeans, create a Java program called Average.java. The program should use the Scanner class to get 4 integers from the user and store them in variables. The program should calculate the average of the 6 numbers as a floating point. Output all of the original input and the calculated average in the Command window. The code is expected to be commented and user-friendly.
Finding the Mean The mean (or average) of a non-empty list of n numbers is the...
Finding the Mean The mean (or average) of a non-empty list of n numbers is the sum of the numbers divided by n. For example, the mean of 2, 7, 3, 9, and 13 is (2+7+3+9+13)/5, or 6.8. Write a function mean that takes as input a non-empty list of numbers (of any length > 0) and returns the mean.
Using C++ design a program that Prompts the User to enter 4 Numbers, then have the...
Using C++ design a program that Prompts the User to enter 4 Numbers, then have the program output those numbers entered in Ascending order. Use "if" statements to create the code...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive...
5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive numbers representing deposits to and negative numbers representing withdrawals from a bank account. Your function should return a list of two floating-point numbers; the first will be the sum of the deposits, and the second (a negative number) will be the sum of the withdrawals. >>> statement([30.95, -15.67, 45.56, -55.00, 43.78]) [120.29, -70.67]
Create a C program that evaluates the function 3x + 7. Your input will consist of...
Create a C program that evaluates the function 3x + 7. Your input will consist of a number of lines, each containing a single integer number. For each number x that is provided in the input, you should output 3x + 7 as a single integer number. Each number your program prints has to occupy a separate line. No other character should be sent to the output other than the digits of the number (and possible sign) and the newline...