Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- void printArray(double *x, int n) {
- for (int i = 0; i < n; i++) {
- cout << setprecision(2) << x[i] << ' ';
- }
- cout << '\n';
- }
- void printMatrix(double x[][100], int n, int m) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cout << setprecision(2) << setw(6) << x[i][j];
- }
- cout << '\n';
- }
- }
- int main() {
- srand(time(NULL));
- setlocale(LC_ALL, "rus");
- double mas[100], arr[100][100], ar[100][100];
- int n, g;
- do {
- cout << "Введите какого порядка матрица: ";
- cin >> n;
- if (n <= 5)
- cout << "Порядок должен быть больше 5!";
- } while (n <= 5);
- int m = n + 1;
- //cout << "Столбец, который нужно вcтавить: ";
- for (int i = 0; i < n; i++) {
- mas[i] = (float)(rand() % 4000 - 2000) / 100;
- //cout << '\n' << mas[i] << " ";
- for (int j = 0; j < m; j++) arr[i][j] = (float)(rand() % 4000 - 2000) / 100;
- }
- g = m + 1;
- cout << "Массив:\n";
- printArray(mas, n);
- cout << "\nИсходная матрица\n";
- printMatrix(arr, n, m);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < g; j++) {
- if (j == 5) {
- ar[i][j] = mas[i];
- for (g = j + 1; g < m + 1; g++) {
- ar[i][g] = arr[i][j];
- j++;
- }
- continue;
- }
- ar[i][j] = arr[i][j];
- }
- }
- cout << "\nИзмененная матрица\n";
- printMatrix(ar, n, g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement