Advertisement
35657

Untitled

Mar 15th, 2024
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. void display(T arr[], int size) {
  7.     for (int i = 0; i < size; i++) {
  8.         cout << arr[i] << " ";
  9.     }
  10.     cout << endl;
  11. }
  12.  
  13. template<typename T>
  14. void average(T arr[], int size) {
  15.     T sum = 0;
  16.     for (int i = 0; i < size; i++) {
  17.         sum += arr[i];
  18.     }
  19.     cout << "Среднее арифметическое массива: " << sum / size << endl;
  20. }
  21.  
  22. int main() {
  23.  
  24.     setlocale(LC_ALL, "ru");
  25.  
  26.     int arr[]{ 1, 3, 7, -4, -2, 4 };
  27.     int size = 6;
  28.     display(arr, size);
  29.     average(arr, size);
  30.  
  31.  
  32.     double arr2[]{ 3.5, 2.5, 3.7, 1.0, 3.3, 7.2 };
  33.     display(arr2, size);
  34.     average(arr2, size);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement