-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGrupa A - Zadatak 02.cpp
62 lines (49 loc) · 1.12 KB
/
Grupa A - Zadatak 02.cpp
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
#include <iostream>
using namespace std;
void upis(int niz[][3])
{
cout << "Unesite matricu: " << endl;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
cin >> niz[i][j];
}
void kopiraj(int niz1[][3], int niz2[][5])
{
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
if(j <= 2) niz2[i][j] = niz1[i][j];
else niz2[i][j] = niz1[i][j-3];
}
}
}
int suma(int niz[], int r)
{
int s = 0;
for(int i = 0; i < r; i++)
s += niz[i];
return s;
}
int main()
{
int niz1[2][3];
int niz2[2][5];
int matrica, red;
int s;
upis(niz1);
kopiraj(niz1, niz2);
do
{
cout << "Izaberite matricu (1/2)" << endl;
cin >> matrica;
cout << "Izaberite red (1/2)" << endl;
cin >> red;
}while((matrica < 1 || matrica > 2) && (red < 1 || red > 2));
if(matrica == 1)
s = suma(niz1[red-1], 3);
else
s = suma(niz2[red-1], 5);
cout << "Suma " << red << ". reda " << matrica << ". matrice je " << s << endl;
return 0;
}