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.

|

## 85 thoughts on “Tasks: Two-dimensional arrays C ++”

1. Angela says:

Hello. but as that's in your 3 Example administered row and column size by?

2. Dmitriy says:

I 2 otherwise invented:
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
const int STROKA = 3;
const int STOLBEC = 4;
you massive[DISCIPLINE][STOLBEC];
int sum_stroki=0, sum_stolbca;
cout << "Вводите элементы массива: " << endl;
//input array
for (int i = 0; i < DISCIPLINE; i )
{
cout << i+1<<"-я строка: " << endl;
for (int j = 0; j > solid[i][j];
}
}
//Output array
for (int i = 0; i < DISCIPLINE; i )
{
for (int j = 0; j < STOLBEC; j )
{
cout << solid[i][j]<<" ";
}
cout << endl;
}
//Output sums lines
for (int i = 0; i < DISCIPLINE; i )
{
for (int j = 0; j < STOLBEC; j )
{
sum_stroki + = massiv[i][j];
}
cout << "Сумма " << i + 1 << "-ой строки: " << sum_stroki << endl;

}
cout << endl;
//Output column sums
for (int j = 0; j < STOLBEC; j )
{
sum_stolbca = 0;
for (int i = 0; i < DISCIPLINE; i )
{
sum_stolbca + = massiv[i][j];
}
cout << "Сумма " << j + 1 << "-го столбца: " << sum_stolbca << endl;
}
}

3. Dmitriy says:

#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
srand(time(NULL));
const int STROKA = 6;
const int STOLBEC = 6;
you massive[DISCIPLINE][STOLBEC];
you massiv_sum_strok[DISCIPLINE];
int sum_stroki,max_sum, max_number=0;
for (int i = 0; i < DISCIPLINE; i )
{
for (int j = 0; j < STOLBEC; j )
{
solid[i][j] = rand() % 90 + 10;
}
}
for (int i = 0; i < DISCIPLINE; i )
{
for (int j = 0; j < STOLBEC; j )
{
cout << solid[i][j] << " ";
}
cout << endl;
}
for (int i = 0; i < DISCIPLINE; i )
{
sum_stroki = 0;
for (int j = 0; j < STOLBEC; j )
{
sum_stroki + = massiv[i][j];

}
massiv_sum_strok[i] = sum_stroki;
cout << "Сумма элементов " << i + 1 << "-ой строки: " << sum_stroki << endl;
}
max_sum = massiv_sum_strok[0];
for (int i = 0; i max_sum)
{
max_sum = massiv_sum_strok[i];
max_number = i;
}
}
cout << "Максимальная сумма элементов строки: " << max_sum << endl;
cout << "Номер строки с максимальной суммой элементов: " << max_number+1;
}
sorry that no komentov:)

4. Georgy says:

Мой ответ на 3-тье задание .
#include
#include
using namespace std;
int main() {
setlocale(LC_ALL,”RUS”);
const int ROW = 3;
const int COL = 4;
int ARR[ROW][COL];
srand(time(NULL));
for (int i = 0; i < ROW; i ) {
for (int g = 0; g < COL; g++) {
ARR[i][g] = rand() % 91 + 10;

}
}
int ARR1[ROW]{};
for (int i = 0; i < ROW; i ) {
int T = 0;
for (int g = 0; g < COL; g++) {

T += ARR[i][g];
ARR1[i] = T;
}
}
int o;
o = ARR1[0];
int p;
p = 0;
for (int i = 1; i < ROW; i ) {
if (O < ARR1[i]) {
o = ARR1[i];
p = i;
}
}
cout << "В строчке " << p << " сумма всех ее элементов наибольшая ";
}