Advertisement
Guest User

Untitled

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