Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- using namespace std;
- void min_max(int* G, int N)
- {
- int min = G[0];
- int max = G[0];
- int numb_min = 0;
- int numb_max = 0;
- for (int i = 0;i < N;i++)
- {
- if (G[i] < min)
- {
- min = G[i];
- numb_min = i;
- }
- if (G[i] > max)
- {
- max = G[i];
- numb_max = i;
- }
- }
- int tmp = min;
- G[numb_min] = max;
- G[numb_max] = tmp;
- for (int i = 0;i < N;i++)
- {
- cout << G[i] << " ";
- }
- }
- int main()
- {
- ifstream file("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text.txt");
- if (!file)
- {
- cout << "File is not open";
- return -1;
- }
- else
- {
- cout << "File is open" << endl;
- const int N = 10;
- int G[N];
- for (int i = 0;i < N;i++)
- {
- file >> G[i];
- cout << G[i] << " ";
- }
- cout << endl;
- min_max(G, N);
- file.close();
- system("pause");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement