Question

In: Computer Science

Write a C++ program to read N numbers. Find sum, product, and average of N numbers

Write a C++ program to read N numbers. Find sum, product, and average of N numbers

Solutions

Expert Solution

#include<iostream>
using namespace std;
int main ()
{ int i,n,pro=1,num ;
float sum=0, avg;
   cout<<" Enter the number of values:";
   cin>>n;
   cout<<"Enter values :";
   for(i=0;i<n;i++)
   {
   cin>>num;
   sum=sum+num;
   pro=pro*num;
   avg=sum/n;
   }
   cout<<"\nSum:"<< sum;
   cout<<"\nProduct:"<< pro;
   cout<<"\nAverage:"<< avg;
}

output:


Related Solutions

in c++ (Sum, average and product of numbers in a file) Suppose that a text file...
in c++ (Sum, average and product of numbers in a file) Suppose that a text file Exercise13_3.txt contains six integers. Write a program that reads integers from the file and displays their sum, average and product. Integers are separated by blanks. Instead of displaying the results on the screen, send the results to an output named using your last name. Example:       Contents of Exercise13_3.txt: 100 95 88 97 71 67 80 81 82             Contents of YourLastName.txt: Your...
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
C++. Write a program that will read in id numbers and place them in an array.The...
C++. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please enter an...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write 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 two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
1. Write MIPS assembly code to sum “n” positive integers. Forexample, n=5, read 5 numbers...
1. Write MIPS assembly code to sum “n” positive integers. For example, n=5, read 5 numbers in memory (“.data” section) and add them together. 2. Write MIPS assembly code to calculate N-factorial. Read n from the memory. (Hint: use “.data” to define the content in a memory location)
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
Write a C++ program to read a collective of integer numbers. I f the number is...
Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number
Write a C program to show sum of 10 elements of array and show the average....
Write a C program to show sum of 10 elements of array and show the average. [10]
The sum of two numbers is 34. a)Find the largest possible product of these numbers.
  1-The sum of two numbers is 34.    a)Find the largest possible product of these numbers.    b)What would be the largest possible product if the sum if the two numbers were "k"? 2-Sixty meters of fencing are used to fence a rectangular garden.    a)Find the dimensions that will give that maximum area.    b)What would be the maximum area if "k" feet of fencing were used in terms of "k"? THANK YOU
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT