Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

#include <iostream> #include <algorithm> const int maxrow = 10; const int maxcol = 10;…

  1. User

    #include #include

    const int max_row = 10; const int max_col = 10;

    using namespace std;

    //lesson 1 void sorting(int arr[max_row][max_col], int row, int col) { for (int i = 0; i < row; ++i) { sort(arr[i], arr[i] + col); } }

    void display_arr(int arr[max_row][max_col],int row, int col) { cout << “LESSON 1: Sorted Arr:\n”; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { cout << arr[i][j] << “\t”; } cout << endl; } }

    int sum_row(int arr[max_row][max_col], int row, int col) { int rowSum = 0;

    for (int j = 0; j < col; ++j) { rowSum += arr[row][j]; } return rowSum;

    }

    int sum_col(int arr[max_row][max_col], int row, int col) { int colSum = 0; for (int i = 0; i < row; ++i) { colSum += arr[i][col]; } return colSum;

    }

    int total_sum(int arr[max_row][max_col], int row, int col) { int totalSum = 0; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { totalSum += arr[i][j]; } } return totalSum; }

    void display_table(int arr[max_row][max_col],int row, int col) { cout << “LESSON 2: CREATE TABLE:\n”; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { cout << arr[i][j] << “\t”; } cout << “|”<< “\t” <<sum_row(arr,i,col) << endl; }

    for(int i = 0; i< col+7; i++) { cout << “----”; } cout << endl;

    for (int i = 0; i < col; i++) { cout << sum_col(arr,row,i) << “\t”;

    }

    cout << “|\t”<< total_sum(arr,row,col);

    }

    int main() { int row, col; cout << "Enter rows: "; cin >> row; cout << "Enter cols: "; cin >> col;

    int arr[max_row][max_col];

    cout << “Enter element:\n”; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { cin >> arr[i][j]; } }

    sorting(arr, row, col);

    display_arr(arr,row,col);

    display_table(arr,row,col);

    return 0; } измени код , чтобы в нем использовались динамические двумерные массивы вместо статических

  2. Assistant

    #include #include

    using namespace std;

    void sorting(int** arr, int row, int col) { for (int i = 0; i < row; ++i) { sort(arr[i], arr[i] + col); } }

    void display_arr(int** arr, int row, int col) { cout << "LESSON 1: Sorted Arr:\n"; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { cout << arr[i][j] << "\t"; } cout << endl; } }

    int sum_row(int** arr, int row, int col) { int rowSum = 0; for (int j = 0; j < col; ++j) { rowSum += arr[row][j]; } return rowSum; }

    int sum_col(int** arr, int row, int col) { int colSum = 0; for (int i = 0; i < row; ++i) { colSum += arr[i][col]; } return colSum; }

    int total_sum(int** arr, int row, int col) { int totalSum = 0; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { totalSum += arr[i][j]; } } return totalSum; }

    void display_table(int** arr, int row, int col) { cout << "LESSON 2: CREATE TABLE:\n"; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { cout << arr[i][j] << "\t"; } cout << "|" << "\t" << sum_row(arr, i, col) << endl; }

    for (int i = 0; i < col + 7; i++) {
        cout << "----";
    }
    cout << endl;
    
    for (int i = 0; i < col; i++) {
        cout << sum_col(arr, row, i) << "\t";
    }
    
    cout << "|\t" << total_sum(arr, row, col);
    

    }

    int main() { int row, col; cout << "Enter rows: "; cin >> row; cout << "Enter cols: "; cin >> col;

    int** arr = new int*[row];
    for (int i = 0; i < row; i++) {
        arr[i] = new int[col];
        cout << "Enter elements for row " << i + 1 << ":\n";
        for (int j = 0; j < col; j++) {
            cin >> arr[i][j];
        }
    }
    
    sorting(arr, row, col);
    
    display_arr(arr, row, col);
    
    display_table(arr, row, col);
    
    for (int i = 0; i < row; i++) {
        delete[] arr[i];
    }
    delete[] arr;
    
    return 0;
    

    }