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 is the type of 'this' pointer? When does it get created?
How to delete array of objects in C++? Proof by C++ code for proper deletion
What is object in oops?
What does catch(…) mean?
Define stl.
How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?
What is vectorial capacity?
Describe exception handling concept with an example?
What is a class in oop?
What is constructor in C++?
How do you declare A pointer to a function which receives nothing and returns nothing
How delete [] is different from delete?
Can main method override?
Can we use this pointer inside static member function?
Will rust take over c++?