Advertisement
Dorreli

Untitled

Jan 20th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <fstream>
  2. #include <stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. void fill_in(int** a, const int N, const int M, ifstream& file)
  7. {
  8. for (int i = 0; i < N; i++)
  9. {
  10. for (int j = 0; j < M; j++)
  11. {
  12. file >> a[i][j];
  13. cout << a[i][j] << "\t";
  14. }
  15. cout << endl;
  16. }
  17. }
  18.  
  19. void print(int** a, const int N, const int M)
  20. {
  21. for (int i = 0; i < N; i++)
  22. {
  23. for (int j = 0; j < M; j++)
  24. {
  25. cout << a[i][j] << "\t";
  26. }
  27. cout << endl;
  28. }
  29. }
  30.  
  31. double arifm_nadgl(int** a, int n, int m)
  32. {
  33. double summ = 0; int k = 0;
  34. for (int i = 0; i < n; i++)
  35. {
  36. for (int j = 0; j < n; j++)
  37. {
  38. if (i < j)
  39. {
  40. summ += a[i][j];
  41. k++;
  42. }
  43. }
  44. }
  45. return summ / k;
  46. }
  47.  
  48. int main()
  49. {
  50. setlocale(0, "Rus");
  51. ifstream file("J:\\Универ\\Программирование\\Практика_txt\\z_12.txt");
  52. if (file.is_open())
  53. {
  54. int N = 10, M = 10;
  55. int** A;
  56. A = new int* [N];
  57. for (int i = 0; i < N; i++)
  58. A[i] = new int[M];
  59. cout << "Матрица A: " << endl;
  60. fill_in(A, N, M, file);
  61. cout << "Среднее арифметическое: " << arifm_nadgl(A, N, M) << endl;
  62. system("pause");
  63. return 0;
  64. }
  65. else
  66. {
  67. cout << "Файл не открыт" << endl;
  68. system("pause");
  69. return 0;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement