fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. using namespace std;
  4.  
  5. double arr_avg(vector<int>& arr, int idx) {
  6. if (idx == arr.size()) return 0;
  7. return double(arr[idx]) / arr.size() + arr_avg(arr, idx + 1);
  8. }
  9.  
  10. void solve() {
  11. vector<int> arr = {1,8,2,10,3};
  12. cout << arr_avg(arr, 0) << endl;
  13. }
  14.  
  15. int main() {
  16. IOS;
  17. solve();
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
4.8