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. 3 a task

    #include
    #include
    #include
    using namespace std;

    int main()
    {
    setlocale(0, “”);

    const int rows = 5;
    const int cols = 10;
    int arr[rows][cols] = {};
    int arr_rows[rows] = {};
    int max = 0;
    int number_row = 0;

    srand(time(NULL));

    for (int i = 0; i < rows; i )
    {
    for (int j = 0; j < cols; j )
    {
    arr[i][j] = 10 + rand() % 91;
    arr_rows[i] += arr[i][j];
    }
    }
    //matrix output
    for (int i = 0; i < rows; i )
    {
    cout << endl;
    for (int j = 0; j < cols; j )
    {
    cout << setw(4) << arr[i][j];
    }
    }
    //outputting an array with sums of strings and finding the maximum
    for (int i = 0; i < rows; i )
    {
    cout << "\nСумма " << i+1 << "-й строки = " << arr_rows[i] < max)
    {
    max = arr_rows[i];
    number_row = i;
    }
    }
    cout << "\nМаксимальная сумма элементов в строке номер " << number_row+1 << endl;
    return 0;
    }

    1. Help solve the task
      Given a two-dimensional array of dimension [n, m], randomly filled. Replace all elements of the first three
      columns into their squares.

      1. #include
        #include

        using namespace std;

        int main()
        {
        setlocale(LC_ALL,(“rus”));

        const int row = 3;
        const int cols = 4;

        int sqare = 0;

        int arr[row][cols] = {};

        srand(time(NULL));

        for (int i = 0; i < row; i )
        {
        cout << "|";
        for (int j = 0; j < cols; j )
        {
        arr[i][j] = rand() % 10;
        cout << arr[i][j] << " ";
        }
        cout << "|" << endl;
        }
        cout << endl;
        for (int i = 0; i < row; i )
        {
        cout << "|" ;
        for (int j = 0; j < 3; j ++ )
        {
        arr[i][j] *= arr[i][j];
        cout << arr[i][j] << " ";
        }
        cout << "|" << endl;
        }

        cout << endl;
        return 0;
        }

  2. #include
    #include
    using namespace std;
    int main()
    {
    srand(time(NULL));
    setlocale(LC_ALL, “ru”);
    const int row = 5;
    const int col = 5;
    int arr[row][col]{};
    int c_row[row]{};
    int max = 0;
    int max_row = 0;
    for (int i = 0; i < row; i )
    {
    for (int j = 0; j < col; j )
    {
    arr[i][j] = 10 + rand() % 91;
    cout << arr[i][j] << " | ";
    c_row[i] += arr[i][j];
    }cout << endl;
    }
    for (int i = 0; i < row; i )
    {
    cout << "Сумма элементов в " << i + 1 << " row " << c_row[i] << endl;
    if (max < c_row[i])
    {
    max = c_row[i];
    max_row++;
    }
    }cout << "Максимальная сумма элементов находится на "<<max_row<<" string and is equal to: " << max << endl;

    return 0;
    }

    1. help solve please
      Given a two-dimensional array of dimension [n, m], randomly filled. Replace all elements of the first three
      columns into their squares.

  3. Help solve the task.
    Given a two-dimensional array of dimension [n, m], randomly filled. Replace all elements of the first three
    columns into their squares.

  4. Help to solve .
    Given a two-dimensional array. Define: is there a negative element in the given array.

    1. srand(time(nullptr));
      const int length = 5;
      int numbers[length][length];
      int negative_numbers = 0;
      for (size_t i = 0; i < length; i )
      {
      for (size_t j = 0; j < length; j )
      {
      numbers[i][j] = -5 + rand() % 26;
      cout << numbers[i][j] << " ";
      if (j == 4)
      {
      cout << endl;
      }
      }
      }
      for (size_t i = 0; i < length; i )
      {
      for (size_t j = 0; j < length; j )
      {
      if (numbers[i][j] < 0)
      {
      negative_numbers++;
      }

      }
      }
      if (negative_numbers == 0)
      {
      cout << "The negative numbers not found…" << endl;
      }

      else
      {
      cout << "Number of negative numbers = " << negative_numbers << endl;
      }

  5. Please help me solve the problem!
    This rectangular matrix A of dimension n × m. Arrange the columns of the matrix in ascending order of the elements of the kth row (1≤ k ≤n).

  6. help solve please. Find the number of positive elements lying on the main diagonal of a square matrix.

  7. Help!adana square matrix, consisting of nxn elements. The matrix contains different values. You must remove the same elements from the matrix.

Leave a Reply

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