-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem #03.txt
More file actions
82 lines (69 loc) · 1.54 KB
/
Copy pathproblem #03.txt
File metadata and controls
82 lines (69 loc) · 1.54 KB
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
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int Randomnumber(int from, int to)
{
int randum = rand() % (to - from + 1) + from;
return randum;
}
void FillMatrixWithRandomNumbers(int arr[3][3], short Rows, short Cols)
{
int sum = 0;
for (short i = 0; i < Rows; i++)
{
for (short j = 0; j < Cols; j++)
{
arr[i][j] = Randomnumber(1, 100);
}
}
}
void PrintMatrix(int arr[3][3], int Rows, int Cols)
{
for (short i = 0; i < Rows; i++)
{
for (short j = 0; j < Cols; j++)
{
cout << setw(3) << arr[i][j] << " ";
}
cout << "\n";
}
}
int RowSum(int arr[3][3], short RowNumber, short Cols)
{
int Sum = 0;
for (short j = 0; j < Cols; j++)
{
Sum += arr[RowNumber][j];
}
return Sum;
}
void SumMatrixRowsInArray(int arr[3][3], int arrsum[3], short Rows, short Cols)
{
for (short i = 0; i < Rows; i++)
{
arrsum[i] = RowSum(arr, i, Cols);
}
}
void PrintRowsSumArray(int arr[3] , int Rows)
{
cout << "\n The following are the sum of each row in the matrix: \n";
for (short i = 0; i < Rows; i++)
{
cout << "Row " << i + 1 << " Sum " << arr[i]<<endl;
}
}
int main()
{
//Seeds the random number genrator in c++, called only once
srand((unsigned)time(NULL));
int arr[3][3];
int arrsum[3];
FillMatrixWithRandomNumbers(arr, 3, 3);
cout << "\n the following is a 3x3 random matrix: \n";
PrintMatrix(arr, 3, 3);
SumMatrixRowsInArray(arr, arrsum, 3, 3);
PrintRowsSumArray(arrsum,3);
system("pause>0");
return 0;
}