Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. using namespace std;
  5. void print(int A[][10], int N)
  6. {
  7. for (int i = 0;i < N;i++)
  8. {
  9. for (int j = 0;j < N;j++)
  10. {
  11. cout << A[i][j] << "\t";
  12. }
  13. cout << endl;
  14. }
  15. }
  16. double sr_arifm(int A[][10], int N)
  17. {
  18.  
  19. double sum = 0;
  20. int kol = 0;
  21. for (int i = 0;i < N;i++)
  22. {
  23. for (int j = 0;j < N;j++)
  24. {
  25. if (i < j)
  26. {
  27. sum += A[i][j];
  28. kol++;
  29. }
  30. }
  31. }
  32. return sum/kol;
  33. }
  34. int main()
  35. {
  36. ifstream file("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text.txt");
  37. if (!file)
  38. {
  39. cout << "File is not open";
  40. return -1;
  41. }
  42. else
  43. {
  44. cout << "File is open" << endl;
  45. const int N = 10;
  46. int A[N][N];
  47. for (int i = 0;i < N;i++)
  48. {
  49. for (int j = 0;j < N;j++)
  50. {
  51. if (!file.eof())
  52. {
  53. file >> A[i][j];
  54. }
  55. }
  56. }
  57. cout << endl;
  58. print(A, N);
  59. cout << endl;
  60. cout << "Sr arifm = " << sr_arifm(A, N)<<endl;
  61. file.close();
  62. system("pause");
  63. return 0;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement