#include<iostream>
using namespace std;
int main(){
int n,i,a[50];
float average,total=0;
cout<<"Enter the total number of elements(max 50)";
cin>>n;
for(i=0;i<n;i++){
cout<<"Enter the "<<i+1<<" number:";
cin>>a[i];
}
for(i=0;i<n;i++){
total=a[i]+total;
}
average=total/n;
cout<<"The sum of the given numbers is "<<total<<endl;
cout<<"The average is "<<average;
return 0;
}
using namespace std;
int main(){
int n,i,a[50];
float average,total=0;
cout<<"Enter the total number of elements(max 50)";
cin>>n;
for(i=0;i<n;i++){
cout<<"Enter the "<<i+1<<" number:";
cin>>a[i];
}
for(i=0;i<n;i++){
total=a[i]+total;
}
average=total/n;
cout<<"The sum of the given numbers is "<<total<<endl;
cout<<"The average is "<<average;
return 0;
}
No comments:
Post a Comment