Advertisement
kxcoze

again_satie

Apr 9th, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. void printArray(double *x, int n) {
  8.     for (int i = 0; i < n; i++) {
  9.         cout << setprecision(2) << x[i] << ' ';
  10.     }
  11.     cout << '\n';
  12. }
  13.  
  14. void printMatrix(double x[][100], int n, int m) {
  15.     for (int i = 0; i < n; i++) {
  16.         for (int j = 0; j < m; j++) {
  17.             cout << setprecision(2) << setw(6) << x[i][j];
  18.         }
  19.         cout << '\n';
  20.     }
  21. }
  22.  
  23. int main() {
  24.     srand(time(NULL));
  25.     setlocale(LC_ALL, "rus");
  26.     double mas[100], arr[100][100], ar[100][100];
  27.     int n, g;
  28.     do {
  29.         cout << "Введите какого порядка матрица: ";
  30.         cin >> n;
  31.         if (n <= 5)
  32.             cout << "Порядок должен быть больше 5!";
  33.     } while (n <= 5);
  34.     int m = n + 1;
  35.     //cout << "Столбец, который нужно вcтавить: ";
  36.     for (int i = 0; i < n; i++) {
  37.         mas[i] = (float)(rand() % 4000 - 2000) / 100;
  38.         //cout << '\n' << mas[i] << " ";
  39.         for (int j = 0; j < m; j++) arr[i][j] = (float)(rand() % 4000 - 2000) / 100;
  40.     }
  41.     g = m + 1;
  42.     cout << "Массив:\n";
  43.     printArray(mas, n);
  44.  
  45.  
  46.     cout << "\nИсходная матрица\n";
  47.     printMatrix(arr, n, m);
  48.     for (int i = 0; i < n; i++) {
  49.         for (int j = 0; j < g; j++) {
  50.             if (j == 5) {
  51.                 ar[i][j] = mas[i];
  52.                 for (g = j + 1; g < m + 1; g++) {
  53.                     ar[i][g] = arr[i][j];
  54.                     j++;
  55.                 }
  56.                 continue;
  57.             }
  58.             ar[i][j] = arr[i][j];
  59.         }
  60.     }
  61.  
  62.     cout << "\nИзмененная матрица\n";
  63.     printMatrix(ar, n, g);
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement