Write a C++ Program to Find Sum and Average of n numbers using for loop.
Answer Posted / hr
Solution:
/* C++ Program to Find Sum and Average of n numbers using for loop */
#include<iostream>
using namespace std;
int main()
{
int i,n,x,sum=0;
float avg;
cout<<"How many numbers u want to enter :: ";
cin>>n;
for(i=1;i<=n;++i)
{
cout<<"
Enter number "<<i<<" :: ";
cin>>x;
sum+=x;
}
avg=(float)sum/(float)n;
cout<<"
Sum of "<<n<<" Numbers :: "<<sum;
cout<<"
Average of "<<n<<" Numbers :: "<<avg;
cout<<"
";
return 0;
}
Output:
/* C++ Program to Find Sum and Average of n numbers using for loop */
How many numbers u want to enter :: 6
Enter number 1 :: 1
Enter number 2 :: 2
Enter number 3 :: 3
Enter number 4 :: 4
Enter number 5 :: 5
Enter number 6 :: 6
Sum of 6 Numbers :: 21
Average of 6 Numbers :: 3.5
Process returned 0
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What information can an exception contain?
Can you declare an array without a size in c++?
What is the difference between Stack and Queue in C++?
When does the c++ compiler create temporary variables?
How do you remove an element from a set in c++?
write a c++ program to create class student having datamember name,Roll_no,age,and branch intilcization all the member using constructor print the all the details on the screen.
Differentiate between late binding and early binding. What are the advantages of early binding?
What size is allocated to the union variable?
How does stack look in function calls? Write a recursive function call, how will the stack look like?
Explain what are accessor methods?
What does the nocreate and noreplace flag ensure when they are used for opening a file?
write a porgram in c++ that reads an integer and print the biggest digit in the number
Why polymorphism is used in oops?
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
What is a map in c++?