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.

115 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;
    }

Leave a Reply to Aisha Cancel reply

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