The basics of programming in c++ for beginners

Tasks: Two-dimensional arrays C ++

To begin to address the tasks, proposed in this article, you need to know that is two-dimensional (multidimensional) arrays . Tasks are arranged from simple to complex. So that, If you're new to programming, start with the first, to better deal with the other.

1. Declare a two-dimensional array, fill integers and show on the screen.

2) Объявить двумерный массив и заполнить его построчно с клавиатуры. После заполнения – показать заполненную матрицу на экран и посчитать сумму элементов отдельно в каждом столбце и каждой строке.

3) Fill two-dimensional array of random numbers 10  to 100. Calculate the sum of the elements separately in each line and determine the line number,  in which this sum is maximal.

Your questions, которые возникли при решении задач, leave comments on this article.

117 thoughts on “Tasks: Two-dimensional arrays C ++

  1. why did you allocate an entire array for the sum of the elements of the array row? why, you can use a regular variable?

  2. #include
    #include
    using namespace std;

    int main (){
    srand(time(NULL));
    const int COL = 7;
    const int ROW = 5;
    int arr[ROW][COL];
    for (int i = 0; i < ROW; i ){
    for (int k = 0; k < COL; k ){
    arr[i][k] = rand() % 100;
    cout << arr[i][k] << '\t';
    }
    cout << endl;
    }
    return 0;
    }

  3. #include
    #include
    using namespace std;

    int main (){
    srand(time(NULL));
    const int COL = 7;
    const int ROW = 5;
    int arr[ROW][COL];
    for (int i = 0; i < ROW; i ){
    for (int k = 0; k < COL; k ){
    arr[i][k] = 10 +rand() % 91;
    cout << arr[i][k] << '\t';
    }
    cout << endl;
    }
    int i;
    int arr[] ={};
    for (int i = 0; i < ROW; i ){
    Sum = 0;
    for (int k = 0; k < COL; k )
    Sum += arr[i][k];
    arr[i] = Sum;
    cout <<"line" << i+1 <<'\t'<<Sum << endl;}
    // max sum value all line
    int max = arrSum[0];
    for (int j = 1; j max)
    max =arrSum[j];
    }
    cout << " max sum value all line: " << max;
    return 0;
    }

  4. solution 3rd tasks
    #include
    using namespace std;
    int main()
    {
    srand(time(NULL));
    int more[5][5];
    int su[5] = {0,0,0,0,0};
    int ch, G, V;
    /* using G we find the max sum
    ch line counter
    We use V to search for a string where the amount is large */
    ch = 0;
    G = your[0];

    for (int x = 0; x < 5; x++) {
    for (int y = 0; Y < 5; and ++) {
    but[x][Y] = 10 + rand() % 100;
    }
    }
    for (int x = 0; x < 5; x++) {
    for (int y = 0; Y < 5; and ++) {
    cout << but[x][Y]<<"…";
    }
    cout <<" "<< endl;
    }
    for (int x = 0; x < 5; x++) {
    for (int y = 0; Y < 5; and ++) {
    are[x] = are[x] + but[x][Y];
    }
    cout << "summa stroki |" << x + 1 << "| = " << are[x] << endl;
    }
    for (int x = 0; x < 5; x++) {
    if (G <= are[x]) {
    G = your[x];

    }

    }
    for (int x = 0; x < 5; x++) {
    V = your[x];
    ch++;
    if (V == G) {
    break;
    }
    }
    cout << "max stroka |" << ch << "|= " << G;
    return 0;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *