fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void input(double* a, int n) {
  7. for (int i = 0; i < n; i++)
  8. cin >> a[i];
  9. }
  10.  
  11. void output(double* a, int n) {
  12. for (int i = 0; i < n; i++)
  13. cout << a[i] << " ";
  14. }
  15.  
  16. double* sum(double* a, double* b, int n) {
  17. auto c = new double[n];
  18.  
  19. for (int i = 0; i < n; i++)
  20. c[i] = a[i] + b[i];
  21.  
  22. return c;
  23. }
  24.  
  25. double length(double* a, int n) {
  26. double sum = 0;
  27.  
  28. for (int i = 0; i < n; i++)
  29. sum += a[i] * a[i];
  30.  
  31. return sqrt(sum);
  32. }
  33.  
  34. double* normalize(double* a, int n) {
  35. auto normalized = new double[n];
  36.  
  37. double length_a = length(a, n);
  38.  
  39. for (int i = 0; i < n; i++)
  40. normalized[i] = a[i] / length_a;
  41.  
  42. return normalized;
  43. }
  44.  
  45. double dot(double* a, double* b, int n) {
  46. double sum = 0;
  47.  
  48. for (int i = 0; i < n; i++)
  49. sum += a[i] * b[i];
  50.  
  51. return sum;
  52. }
  53.  
  54. double distance(double* a, double* b, int n) {
  55. double sum = 0;
  56.  
  57. for (int i = 0; i < n; i++)
  58. sum += pow(b[i] - a[i], 2);
  59.  
  60. return sqrt(sum);
  61. }
  62.  
  63. double average(double* a, int n) {
  64. double sum = 0;
  65.  
  66. for (int i = 0; i < n; i++)
  67. sum += a[i];
  68.  
  69. return sum / n;
  70. }
  71.  
  72. int main() {
  73. int n;
  74. cin >> n;
  75.  
  76. auto a = new double[n];
  77.  
  78. input(a, n);
  79.  
  80. cout << average(a, n);
  81.  
  82. return 0;
  83. }
  84.  
Success #stdin #stdout 0s 5284KB
stdin
2
0 1
stdout
0.5