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.
You can code for the same task, ale in javascript?
Are there two-dimensional arrays in Javascript??)
why did you allocate an entire array for the sum of the elements of the array row? why, you can use a regular variable?
#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;
}
#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;
}
a son
what's with the code ???
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;
}