MohamedAbdel3al

average

Aug 21st, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <bits/stdc++.h>
  4. using namespace std ;
  5. typedef long long ll ;
  6.  
  7. void ABDEL3AL () {
  8. ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr) ;
  9. #ifndef ONLINE_JUDGE
  10. freopen("input.txt" , "r" ,stdin) , freopen("output.txt" , "w" , stdout) ;
  11. #endif
  12. }
  13.  
  14. float average (double arr[] , int n) {
  15. float sum = 0 ;
  16. for (int i = 0; i < n; i++) sum += arr[i] ;
  17. return sum / n ;
  18. }
  19.  
  20.  
  21. int main() {
  22. ABDEL3AL() ;
  23. int n ;
  24. cin >> n ;
  25. double arr[n] ;
  26. for (int i = 0; i < n && cin >> arr[i]; i++);
  27. cout << fixed << setprecision(6) << average(arr , n) ;
  28.  
  29.  
  30. return 0;
  31.  
  32. }
  33.  
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment