Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <ctime>
- #include <clocale>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- #define ROW 3
- #define COLUMN 3
- int main() {
- setlocale(LC_ALL, "Russian");
- srand(time(0));
- int arr[ROW][COLUMN];
- cout << "Исходный массив: " << endl;
- for (int i = 0; i < ROW; i++) {
- for (int j = 0; j < COLUMN; j++) {
- arr[i][j] = rand() % 100;
- cout << arr[i][j] << "\t";
- }
- cout << endl;
- }
- int min1 = arr[0][0];
- int min2 = arr[0][0];
- int min3 = arr[0][0];
- for (int i = 0; i < ROW; i++) {
- for (int j = 0; j < COLUMN; j++) {
- if (arr[i][j] < min1) {
- min1 = arr[i][j];
- }
- }
- }
- for (int i = 0; i < ROW; i++) {
- for (int j = 0; j < COLUMN; j++) {
- if (arr[i][j] < min2 && arr[i][j] > min1) {
- min2 = arr[i][j];
- }
- }
- }
- for (int i = 0; i < ROW; i++) {
- for (int j = 0; j < COLUMN; j++) {
- if (arr[i][j] < min3 && arr[i][j] > min2) {
- min3 = arr[i][j];
- }
- }
- }
- cout << "Минимальный элемент: " << min1 << endl;
- cout << "Два элемента, ближайших к минимальному: " << min2 << " " << min3 << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement