Advertisement
satriafu5710

Menghitung Nilai Rerata dengan Array C++

Nov 18th, 2021
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int n, x[10];
  8.     float jumlah, rerata;
  9.  
  10.     cout << "\n\t Menghitung Rerata Nilai dengan Array \n\n";
  11.  
  12.     cout << " Inputkan Batas Nilai : ";
  13.     cin >> n;
  14.     cout << endl;
  15.  
  16.     for (int i = 1; i <= n; i++)
  17.     {
  18.  
  19.         cout << " Nilai ke-" << i << " : ";
  20.         cin >> x[i];
  21.     }
  22.  
  23.     cout << "\n Isi Datanya : ";
  24.     for (int i = 1; i <= n; i++)
  25.     {
  26.  
  27.         cout << x[i] << ", ";
  28.     }
  29.  
  30.     jumlah = 0;
  31.     for (int i = 1; i <= n; i++)
  32.     {
  33.  
  34.         jumlah = jumlah + x[i];
  35.     }
  36.  
  37.     rerata = jumlah / n;
  38.     cout << "\n\n Nilai Reratanya : " << rerata;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement