#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
const int MatrixSize = 3;
int ourMatrix[MatrixSize][MatrixSize] = {};
int rowSum[MatrixSize] = {}; // для записи суммы по строкам
int columnSum[MatrixSize] = {}; // ... по столбцам
cout << "Заполните матрицу " << MatrixSize << 'х' << MatrixSize << " числами построчно.\n";
for (int rowNum = 0; rowNum < MatrixSize; rowNum++)
{
for (int columnNum = 0; columnNum < MatrixSize; columnNum++)
{
cout << rowNum + 1 << "-я строка ";
cout << columnNum + 1 << "-й столбец: ";
cin >> ourMatrix[rowNum][columnNum];
}
cout << endl;
}
// вывод на экран + подсчет суммы
for (int rowNum = 0; rowNum < MatrixSize; rowNum++)
{
cout << " | ";
for (int columnNum = 0; columnNum < MatrixSize; columnNum++)
{
cout << setw(4) << ourMatrix[rowNum][columnNum] << " ";
rowSum[rowNum] += ourMatrix[rowNum][columnNum];
columnSum[rowNum] += ourMatrix[columnNum][rowNum];
}
cout << "|" << endl;
}
cout << "\nСумма по строкам!\n";
for (int i = 0; i < MatrixSize; i++)
{
cout << i + 1 << "-я строка: " << rowSum[i] << endl;
}
cout << "\nСумма по столбцам!\n";
for (int i = 0; i < MatrixSize; i++)
{
cout << i + 1 << "-й столбец: " << columnSum[i] << endl;
}
return 0;
}
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