Facebook
From 210505, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 87
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4.  
  5. {
  6.    int arr[100],i,n,sum=0;
  7.    cout<<"Enter the number of elements: ";
  8.    cin>>n;
  9.    cout<<"Enter the value of elements: "<<endl;
  10.    
  11.    for(i=0;i<n;i++)
  12.    {
  13.      cin>>arr[i];
  14.    }
  15.  
  16.    for(i=0;i<n;i++)
  17.    {
  18.     sum=sum+arr[i];
  19.    }
  20.     cout<<"Sum of elements is: "<<sum <<endl;
  21.  
  22. float average;
  23.  
  24.  
  25. for(i = 0; i < n; i++)
  26.  
  27. average = (float)sum / n;
  28. cout << "Average: " << average;
  29.  
  30. return 0;
  31. }