-
Notifications
You must be signed in to change notification settings - Fork 0
/
1. Fungsi rata-rata.cpp
51 lines (39 loc) · 1.03 KB
/
1. Fungsi rata-rata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// MENGHITUNG RATA-RATA bersama dengan indeks A
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int score[100];
int highThanAv[100];
int n;
// Fungsi rekursif untuk a[]
double recAvg(int a[], int i, int n)
{
if (i == n-1)
return a[i];
if (i == 0)
return ((a[i] + recAvg(a, i+1, n))/n);
return (a[i] + recAvg(a, i+1, n));
}
double average(int a[], int n)
{
return recAvg(a, 0, n);
}
int main()
{
int i, jml;
cout << "masukkan n= ";
cin >> n;
for(int i=0; i < n; i++){
cout << "masukkan nilai ke-" << i+1 << " ";
cin >> score[i];
}
cout << "Rata-rata = " << average(score, n) << endl;
for(int i=0; i < n; i++){
if(score[i] > average(score,n)){
highThanAv[i]= score[i];
cout << highThanAv[i] << " A" << endl;
jml = jml + count(highThanAv,highThanAv+n, highThanAv[i]);
}
} cout << jml << " mahasiswa di atas rata-rata";
return 0;
}