Advertisement
Guest User

Untitled

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