Advertisement
diiankka

Lab7

Dec 13th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     //setlocale(LC_ALL, "Russian");
  11.     SetConsoleOutputCP(1251);
  12.     SetConsoleCP(1251);
  13.     long n;
  14.     char ex = 'n';
  15.     do {
  16.         cout << "Введите номер задачи (1 или 2):\n";
  17.         char task;
  18.         cin.ignore(100, '\n');
  19.         cin >> task;
  20.         /*cout << "Введите n" << endl;
  21.         cin.ignore(100, '\n');
  22.         cin >> n;*/
  23.         switch (task)
  24.         {
  25.         case '1':
  26.         {
  27.             int const n = 8, m = 10;
  28.             int k;
  29.             double mas[n][m];
  30.             cout << "Enter k" << endl;
  31.             cin >> k;
  32.             cout << "Enter mas" << endl;
  33.             for (int i = 0; i < n; i++)
  34.                 for (int j = 0; j < m; j++)
  35.                     //cin >> mas[i][j];
  36.                     mas[i][j] = rand() % 1000 / 100.0;
  37.             for (int i = 0; i < n; i++) {
  38.                 for (int j = 0; j < m; j++) {
  39.                     cout << mas[i][j] << "\t";
  40.                 }
  41.                 cout << endl;
  42.             }
  43.             double max = mas[0][0];
  44.             double maxk = mas[k - 1][0];
  45.             for (int i = 0; i < n; i++)
  46.                 for (int j = 0; j < m; j++)
  47.                     if (mas[i][j] > max)
  48.                         max = mas[i][j];
  49.             cout << "max = " << max << endl;
  50.            
  51.                 for (int j = 0; j < m; j++)
  52.                     if (mas[k-1][j] > maxk)
  53.                         maxk = mas[k-1][j];
  54.             cout << "maxk = " << maxk << endl;
  55.             double r = maxk / max;
  56.             cout << r << endl;
  57.         }
  58.         break;
  59.         case '2':
  60.         {
  61.             int const n = 11;
  62.  
  63.             double mas[n][n];
  64.             for (int i = 0; i < n; i++)
  65.                 for (int j = 0; j < n; j++)
  66.                     //cin >> mas[i][j];
  67.                     mas[i][j] = rand() % 100; // 100.0;
  68.             cout << "mas:" << endl;
  69.             for (int i = 0; i < n; i++) {
  70.                 for (int j = 0; j < n; j++) {
  71.                     cout << mas[i][j] << " ";
  72.                 }
  73.                 cout << endl;
  74.             }
  75.             for (int i = 0; i < 6; i++)
  76.             {
  77.                 for (int j = 5+i; j < 11; j++) {
  78.                     mas[i][j] = 1;
  79.                 }
  80.             }
  81.             cout << "New mas" << endl;
  82.             for (int i = 0; i < n; i++) {
  83.                 for (int j = 0; j < n; j++) {
  84.                     cout << mas[i][j] << " ";
  85.                 }
  86.                 cout << endl;
  87.             }
  88.         }
  89.         break;
  90.         default: {cout << "Нет такой задачи.\n"; } break;
  91.         }
  92.         cout << "Если вы хотите выйти, введите \'y\', в противном случае - любую другую клавишу" << endl;
  93.         cin.ignore(100, '\n');
  94.         cin >> ex;
  95.     } while (ex != 'y');
  96.     return 0;
  97.     system("pause");
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement