25.12.2013, 19:31. Просмотров 189. Ответов 2
Очень прошу помощи, что исправить в коде чтобы он считал сумму строк матрицы, если номера строк заданы целочисленным вектором.
Часть с суммой(составила только по всем строкам, не то что нужно)
C++ |
1
2
3
4
5
6
7
8
| for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
temp[i] += a[i][j];
cout << temp[i] << "\t";
} |
|
Полный код
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
| #include "stdafx.h"
#include "iostream";
#include <stdio.h>
#include <conio.h>
#include <string>
#include <iomanip>
using namespace std;
void perestanovka(double **a, int n, int m)
{
int i, j, k, h;
int temp[100];
// Сортируем методом выбора.
for (j = 0; j < m; j++)
{
for (i = 0; i < n; i++)
temp[j] += a[i][j];
}
for (j = 0; j < m; j++)
{
for (k = j + 1; k < m; k++)
{
if (temp[j] > temp[k])
{
h = temp[j];
temp[j] = temp[k];
temp[k] = h;
for (i = 0; i < n; i++)
{
h = a[i][j];
a[i][j] = a[i][k];
a[i][k] = h;
}
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
double **a;
int n, m, temp[100];
int i, j,k,h;
cout << " Vvedite kolichestvo strok n= \n";
cin >> n;
cout << "Vvedite kolichestvo stolbchov m=\n";
cin >> m;
cout << "\n";
cout << "\n\n Vvdodim postrochno cheres probel \t";
cout << "\n";
a = new double*[n];
for (i = 0; i < n; i++)
cout << ">\t";{
a[i] = new double[m];
for (j = 0; j < m; j++)
cin >> a[i][j];
}
cout << "\n";
cout << "Kontrolnai matricha:\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
cout << setw(4) << a[i][j];
cout << "\n";
}
cout << "\n";
perestanovka(a, i, j);
cout << "Otsortirovannai matrich:\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cout << setw(10) << right << a[i][j];
}
cout << "\n";
}
cout << "\n" << "\n";
for (j = 0; j < 100; j++)
temp[j] = 0;
cout << "Summa elementov strok:\n";
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
temp[i] += a[i][j];
cout <<right<<setw(15)<< temp[i] << "\t";
}
_getch();
return 0;
} |
|
Буду очень признательна за помощь