Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- const int N = 10;
- const int NUMB_MAX = 5;
- int A[N] = { 1, 10, -2, 100, 50, 43, -32, 65, 16, 1 };
- int B[NUMB_MAX];
- cout << "Выберите способ ввода элементов массива\r\n"
- "0 - Инициализация в коде\r\n"
- "1 - Заполнение случайными числами\r\n"
- "2 - Ввод с клавиатуры\r\n";
- int inp_method;
- cin >> inp_method;
- enum
- {
- fill_in_code,
- fill_rand,
- fill_keyboard,
- };
- switch (inp_method) {
- case fill_in_code:
- break;
- case fill_rand:
- srand(static_cast<int>(time(0)));
- for (int i = 0; i < N; i++)
- A[i] = rand() % 101 - rand() % 101;
- break;
- case fill_keyboard:
- for (int i = 0; i < N; i++)
- cin >> A[i];
- break;
- default:
- return 0;
- }
- cout << "Исходный массив:" << endl;
- for (int i = 0; i < N; i++) {
- cout << setw(5) << A[i];
- }
- cout << endl;
- for (char i = 0; i < NUMB_MAX; i++) {
- B[i] = A[i];
- }
- for (int i = NUMB_MAX; i < N; i++) {
- int a = A[i];
- int min_ind = 0;
- for (char k = 0; k < NUMB_MAX; k++) {
- if (B[k] < B[min_ind])
- min_ind = k;
- }
- if (a > B[min_ind]) {
- B[min_ind] = a;
- }
- }
- cout << "5 Наибольших элементов:" << endl;
- for (int i = 0; i < NUMB_MAX; i++) {
- cout << setw(5) << B[i];
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement