Facebook
From Sajjad hossain, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 106
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cout << "The number of elements" << endl;
  8.     cin >> n;
  9.     cout << "Enter the array" << endl;
  10.  
  11.     int a[100];
  12.     int sum = 0; // Declaration of sum variable
  13.     for(int i = 0; i < n; ++i){
  14.         cin >> a[i];
  15.         sum += a[i];
  16.     }
  17.     cout << "The sum is " << sum << endl;
  18.     float avg = float(sum) / n;
  19.     cout << "The average is " << avg << endl;
  20.  
  21.     return 0;
  22. }
  23.