Write a C++ Program to Find Sum and Average of n numbers using for loop.
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 |
What is the 4 difference between delete[] and delete?
What Are The Differences Between A C++ Struct And C++ Class?
What is a class in C++?
0 Answers Amazon, TCS, UGC Corporation,
Declare a pointer to a function that takes a char pointer as argument and returns a void pointer.
How to convert integer to string in C++
What is Advantage and Use of THIS pointer in C++ – Scenarios?
Write a syntax and purpose of switch statement.
What is the difference between virtual functions and pure virtual functions?
What is Boyce Codd Normal form?
What are string library functions(syntax).
Write a C++ program to print strings in reverse order.
Write a C++ Program to find Square Root of a number using sqrt() function.