Advertisement
awsmpshk

Untitled

Mar 21st, 2020
175
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. void createMas(T**& mas, int n) {
  7. mas = new T * [n];
  8. for (int i = 0; i < n; ++i) {
  9. mas[i] = new T[n];
  10. for (int j = 0; j < n; ++j) {
  11. cin >> mas[i][j];
  12. }
  13. }
  14. }
  15.  
  16. template <typename T>
  17. void printMas(T** mas, int n) {
  18. for (int i = 0; i < n; ++i) {
  19. for (int j = 0; j < n; ++j) {
  20. cout << mas[i][j] << " ";
  21. }
  22. cout << endl;
  23. }
  24. }
  25.  
  26. template <typename T>
  27. double averageAriphm(T** mas, int n) {
  28. int cnt = 0;
  29. double av_sum = 0;
  30. for (int i = 0; i < n; ++i) {
  31. for (int j = 0; j < n; ++j) {
  32. if (j > i) {
  33. cnt++;
  34. av_sum += mas[i][j];
  35. }
  36. }
  37. }
  38. av_sum /= cnt;
  39. return av_sum;
  40. }
  41.  
  42. template <typename T>
  43. void deleteMas(T** mas, int n) {
  44. for (int i = 0; i < n; ++i) {
  45. delete[] mas[i];
  46. }
  47. delete[] mas;
  48. }
  49.  
  50. int main() {
  51. int** a;
  52. int n1;
  53. cin >> n1;
  54. createMas(a, n1);
  55. double** b;
  56. int n2;
  57. cin >> n2;
  58. createMas(b, n2);
  59. cout << averageAriphm(a, n1) << " " << averageAriphm(b, n2) << endl;
  60. cout << endl;
  61. printMas(a, n1);
  62. printMas(b, n2);
  63. deleteMas(a, n1);
  64. deleteMas(b, n2);
  65. return 0;
  66. }
Advertisement
RAW Paste Data Copied
Advertisement