@sandye51
программист С++
686 / 591 / 39
Регистрация: 19.12.2010
Сообщений: 2,016
|
24.06.2011, 13:51
|
|

Сообщение от WresDAG.
1) В каком столбце массива сумма элементов меньше: в первом или в последнем;
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| #include <iostream>
#include <conio.h>
#include <locale>
#include <stdlib.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
unsigned int m, n;
cout << "Введите размер матрицы (m, n)" << endl;
cin >> m >> n;
double** matrix = new double*[m];
cout << "Введите матрицу" << endl;
for (unsigned int i = 0; i < m; ++i)
{
matrix[i] = new double[n];
for (unsigned int j = 0; j < n; ++j)
cin >> matrix[i][j];
}
double s1(0), sn(0);
for (unsigned int i = 0; i < m; ++i)
{
s1 += matrix[i][0];
sn += matrix[i][n - 1];
}
if (s1 > sn)
cout << "В первом столбце больше" << endl;
else
if (s1 < sn)
cout << "В первом столбце меньше" << endl;
else
cout << "Суммы равны" << endl;
_getch();
for (unsigned int i = 0; i < m; ++i)
delete[]matrix[i];
delete[]matrix;
return EXIT_SUCCESS;
} |
|
Добавлено через 2 минуты

Сообщение от WresDAG.
2) В какой строке массива сумма элементов больше: во второй или в третьей?
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| #include <iostream>
#include <conio.h>
#include <locale>
#include <stdlib.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
unsigned int m, n;
cout << "Введите размер матрицы (m, n)" << endl;
cin >> m >> n;
double** matrix = new double*[m];
cout << "Введите матрицу" << endl;
for (unsigned int i = 0; i < m; ++i)
{
matrix[i] = new double[n];
for (unsigned int j = 0; j < n; ++j)
cin >> matrix[i][j];
}
double s2(0), s3(0);
for (unsigned int j = 0; j < n; ++j)
{
s2 += matrix[1][j];
s3 += matrix[2][j];
}
if (s2 > s3)
cout << "Во второй строке больше" << endl;
else
if (s2 < s3)
cout << "Во второй строке меньше" << endl;
else
cout << "Суммы равны" << endl;
_getch();
for (unsigned int i = 0; i < m; ++i)
delete[]matrix[i];
delete[]matrix;
return EXIT_SUCCESS;
} |
|
1
|