Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include "Windows.h"
  5. #include <string>
  6.  
  7. using namespace std;
  8. bool p = true;
  9. void prog_1() {
  10.     double n,j;
  11.     cout << "Введите кол-во элементов массива" << endl;
  12.     cin >> n;
  13.     cout << "Введите элементы массива" << endl;
  14.     if ((round(n) == n)&&(n>0)) {
  15.         int *mass = new int[round(n)];
  16.         for (int i = 0; i < n; i++)
  17.         {
  18.             j = 0;
  19.             cin >> j;
  20.             if (round(j) == j) {
  21.                 mass[i] = round(j);
  22.             }
  23.             else {
  24.                 p = false;
  25.                 return;
  26.             }
  27.         }
  28.         for (int i = 0; i < n; i++)
  29.         {
  30.             if (mass[i] % 2 != 0) {
  31.                 mass[i]++;
  32.             }
  33.         }
  34.         for (int i = 0; i < n; i++) {
  35.             cout << mass[i] << "\t";
  36.         }
  37.         p = true;
  38.     }
  39.     else {
  40.         p = false;
  41.         return;
  42.     }
  43. }
  44. void prog_2() {
  45.     double j = 0;
  46.     double t = 0;
  47.     int countA = 0;
  48.     int countB = 0;
  49.     double massB[5];
  50.     double massA[5];
  51.     cout << "Введите элементы массива A" << endl;
  52.     for (int i = 0; i < 5; i++)
  53.     {
  54.         cin >> massA[i];
  55.     }
  56.     cout << "Введите элементы массива B"<< endl;
  57.     for (int i = 0; i < 5; i++)
  58.     {
  59.         cin >> massB[i];
  60.     }
  61.     cout << "Введите значение t" << endl;
  62.     cin >> t;
  63.     for (int i = 0; i < 5; i++)
  64.     {
  65.         if (massA[i] > t) {
  66.             countB++;
  67.         }
  68.         if (massB[i] > t) {
  69.             countB++;
  70.         }
  71.     }
  72.     if (countA < countB) {
  73.         for (int i = 0; i < 5; i++)
  74.         {
  75.             cout << massA[i] << "\t";
  76.         }
  77.         cout << endl;
  78.         for (int i = 0; i < 5; i++)
  79.         {
  80.             cout << massB[i] << "\t";
  81.         }
  82.     }
  83.     else {
  84.         for (int i = 0; i < 5; i++)
  85.         {
  86.             cout << massB[i] << "\t";
  87.         }
  88.         cout << endl;
  89.         for (int i = 0; i < 5; i++)
  90.         {
  91.             cout << massA[i] << "\t";
  92.         }
  93.     }
  94.     p = true;
  95. }
  96. void prog_3() {
  97.     double n;
  98.     double u;
  99.     cout << "Введите кол-во строк и столбцов массива" << endl;
  100.     cin >> n;
  101.     double sum = 0;
  102.     if ((round(n) == n)&&(n>0)) {
  103.         double **mass;
  104.         mass = new double *[trunc(n)];
  105.         for (int i = 0; i < n; i++)
  106.             mass[i] = new double [trunc(n)];
  107.         cout << "Введите элементы массива" << endl;
  108.         for (int i = 0; i < n; i++)
  109.         {
  110.             for (int j = 0; j < n; j++)
  111.             {
  112.                 cin >> u;
  113.                 mass[i][j] = u;
  114.             }
  115.         }
  116.         for (int i = 0; i < n; i++)
  117.         {
  118.             for (int j = 0; j < n; j++)
  119.             {
  120.                 if (i > j) {
  121.                     sum += mass[i][j];
  122.                 }
  123.             }
  124.         }
  125.         p = true;
  126.         cout << "Сумма элементов ниже гл. диагонали равна " << sum;
  127.     }
  128.     else {
  129.         p = false;
  130.         return;
  131.     }
  132. }
  133. int main()
  134. {
  135.     SetConsoleCP(1251);
  136.     SetConsoleOutputCP(1251);
  137.     do {
  138.         prog_1();
  139.     } while (p = false);
  140.     cout << endl;
  141.     do {
  142.         prog_2();
  143.     } while (p = false);
  144.     cout << endl;
  145.     do {
  146.         prog_3();
  147.     } while (p = false);
  148.     cout << endl;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement