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;
}
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “RU”);
srand(time(NULL));
const int COL = 3;
const int ROW = 3;
int arr[COL][ROW];
//Filling
for (int i = 0; i < COL; i )
{
for (int j = 0; j < ROW; j )
{
arr[i][j] = 10 + rand() % 91;
}
}
//Conclusion
for (int i = 0; i < COL; i )
{
for (int j = 0; j < ROW; j )
{
cout << arr[i][j] << " | ";
}
cout << endl;
}
cout << endl;
int sum[3] = {0,0,0};
int summa = 0;
int temp = 0;
//Count
for (int i = 0; i <ROW; i )
{
summa =0 ;
for (int j = 0; j < COL; j )
{
summa += arr[j][i];
}
cout << "строчка " << i + 1 << " = "
<< sum<<endl;
}
int i = 0;
for ( i = 0; i < ROW; i )
{
sum[i];
for (int j = 0; j sum[1] and sum[0] > sum[2])
{
temp = sum[0];
}
if (sum[1] > sum[0] and sum[1] > sum[2])
{
temp = sum[1];
}
if (sum[2] > sum[0] and sum[2] > sum[1])
{
temp = sum[2];
}
}
cout << " max " << "summa " << temp;
return 0;
}
I know the code, it turned out to be shit, I’ll improve my knowledge