Programming Examples
Cpp program to input 10 integer numbers and find their sum and average
Write a cpp program to input 10 integer numbers and find their sum and average
Solution
#include<iostream>
using namespace std;
int main(){
int num[10],a,sum=0;
float avg;
cout<<"Enter 10 integer numbers"<<endl;
for(a=0;a<10;a++)
{
cin>>num[a];
}
cout<<"List of elements :";
for(a=0;a<10;a++)
{
sum+=num[a];
cout<<num[a]<<"\t";
}
avg=float(sum/10);
cout<<"\nSum is "<<sum<<endl;
cout<<"Average is "<<avg;
return 0;
}
Output
List of elements : 2Â Â Â 3Â Â Â Â 2Â Â Â Â 3Â Â Â Â 2Â Â Â Â 3Â Â Â Â 2Â Â Â Â 3Â Â Â Â 2Â Â Â Â 3
Sum is 25
Average is 2