Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <Windows.h>
- #include <cmath>
- using namespace std;
- int main()
- {
- //setlocale(LC_ALL, "Russian");
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- long n;
- char ex = 'n';
- do {
- cout << "Введите номер задачи (1, 2 или 3):\n";
- char task;
- cin.ignore(100, '\n');
- cin >> task;
- /*cout << "Введите n" << endl;
- cin.ignore(100, '\n');
- cin >> n;*/
- switch (task)
- {
- case '1':
- {
- int n, k = 0;
- cout << "Enter n" << endl;
- cin >> n;
- float* mas;
- mas = new float[n];
- float max = mas[0];
- cout << "Enter mas" << endl;
- for (int i = 0; i < n; i++) {
- cin >> mas[i];
- if (max < mas[i]) {
- max = mas[i];
- k = i;
- }
- }
- for (int i = 0; i < n; i++) {
- if (i < k)
- mas[i] = mas[i + 1];
- else
- mas[i] = 0;
- }
- for (int i = 0; i < n; i++) {
- cout << mas[i] << " ";
- }
- cout << endl;
- delete[]mas;
- }
- break;
- case '2':
- {
- int n, k = 0;
- cout << "Enter n" << endl;
- cin >> n;
- float *mas = new float[n];
- cout << "Enter mas" << endl;
- for (int i = 0; i < n; i++) {
- cin >> mas[i];
- }
- float min = mas[1];
- for (int i = 1; i < n; i++)
- if (min > mas[i]) {
- min = mas[i];
- k = i;
- }
- for (int i = 1; i < k; i++)
- for (int j = 1; j < k - i; j++)
- if (mas[j] > mas[j + 1]) {
- int t = mas[j];
- mas[j] = mas[j + 1];
- mas[j + 1] = t;
- }
- for (int i = 0; i < n; i++) {
- cout << mas[i] << " ";
- }
- cout << endl;
- delete[]mas;
- }
- break;
- case '3':
- {
- int n, j = 0;
- int *mas2 = nullptr;
- int k = 0;
- int a;
- cout << "Enter n" << endl;
- cin >> n;
- int* mas1 = new int[n];
- cout << "Enter mas" << endl;
- for (int i = 0; i < n; i++)
- cin >> mas1[i];
- for (int i = 0; i < n; i++)
- if (mas1[i] % 2 == 0) {
- k++;
- a = i;
- }
- if (k != 0)
- mas2 = new int[n - 1];
- else {
- cout << "В массиве нет четных чисел" << endl;
- system("pause");
- }
- for (int i = 0; i < n; i++) {
- if (i < a) {
- mas2[j] = mas1[i];
- j++;
- }
- else {
- mas2[j] = mas1[i + 1];
- j++;
- }
- }
- for (int i = 0; i < n - 1; i++) {
- cout << mas2[i] << " ";
- }
- cout << endl;
- delete[]mas1;
- delete[]mas2;
- }
- break;
- default: {cout << "Нет такой задачи.\n"; } break;
- }
- cout << "Если вы хотите выйти, введите \'y\', в противном случае - любую другую клавишу" << endl;
- cin.ignore(100, '\n');
- cin >> ex;
- } while (ex != 'y');
- return 0;
- system("pause");
- }
Add Comment
Please, Sign In to add comment