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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad