fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n, sum = 0;
  5. cout << "Enter the number of elements: ";
  6. cin >> n;
  7. int arr[n];
  8. cout << "Enter elements: ";
  9. for (int i = 0; i < n; ++i) {
  10. cin >> arr[i];
  11. sum += arr[i];
  12. }
  13. double average = (double)sum / n;
  14. cout << "Average = " << average << endl;
  15. return 0;
  16. }
Success #stdin #stdout 0.04s 25648KB
stdin
Standard input is empty
stdout
#include <iostream>
using namespace std;
int main() {
 int n, sum = 0;
 cout << "Enter the number of elements: ";
 cin >> n;
 int arr[n];
 cout << "Enter elements: ";
 for (int i = 0; i < n; ++i) {
 cin >> arr[i];
 sum += arr[i];
 }
 double average = (double)sum / n;
 cout << "Average = " << average << endl;
 return 0;
}