Advertisement
malixds_

inf12_2arr

Dec 5th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main() {
  5.     srand(time(NULL));
  6.     setlocale(LC_ALL, "ru");
  7.     const int ROW = 6;
  8.     const int COL = 6;
  9.     float a[ROW][COL];
  10.     float b[3][6];
  11.     int ans;
  12.     bool x;
  13.     cout << "Нажмите 1, если Вы хотите заполнить матрицу самостоятельно" <<
  14.         " и 0, если требуется автоматическое её заполнение:";
  15.     cin >> ans;
  16.     if (ans == 1) {
  17.         for (int i = 0; i < ROW; i++) {
  18.             for (int j = 0; j < COL; j++) {
  19.                 cin >> a[i][j];
  20.             }
  21.         }
  22.         for (int i = 0; i < ROW; i++) {
  23.             cout << endl;
  24.             for (int j = 0; j < COL; j++) {
  25.                 cout << a[i][j] << " ";
  26.             }
  27.         }
  28.     }
  29.     else if (ans == 0) {
  30.         for (int i = 0; i < ROW; i++) {
  31.             int randNum = rand() % 100;
  32.             for (int j = 0; j < COL; j++) {
  33.                 a[i][j] = rand() % 100;
  34.             }
  35.         }
  36.         for (int i = 0; i < ROW; i++) {
  37.             cout << endl;
  38.             for (int j = 0; j < COL; j++) {
  39.                 cout << a[i][j] << " ";
  40.             }
  41.         }
  42.     }
  43.     cout << endl;
  44.         for (int j = 0; j < COL; j++) {
  45.             if (a[0][j] == 0) {
  46.                 cout << 0 << " ";
  47.             }
  48.             else {
  49.                 cout << fixed << setprecision(1) << a[1][j] / a[0][j] << " ";
  50.             }
  51.         }
  52.         cout << endl;
  53.         for (int j = 0; j < COL; j++) {
  54.             if (a[2][j] == 0) {
  55.                 cout << 0 << " ";
  56.             }
  57.             else {
  58.                 cout << fixed << setprecision(1) << a[3][j] / a[2][j] << " ";
  59.             }
  60.         }
  61.         cout << endl;
  62.         for (int j = 0; j < COL; j++) {
  63.             if (a[4][j] == 0) {
  64.                 cout << 0 << " ";
  65.             }
  66.             else {
  67.                 cout << fixed << setprecision(1) << a[5][j] / a[4][j] << " ";
  68.             }
  69.         }
  70.         cout << endl;
  71.         //в итоге получилось создать массив и делить четные строки на нечетные
  72.         //теперь нужно либо видоизменить старый массив и сделать 3x6
  73.         //либо создать новый и поместить туда результат деления
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement