Repository navigation
Expand file tree
/
Copy pathSolution-01.cpp
More file actions
79 lines (66 loc) · 1.68 KB
/
Copy pathSolution-01.cpp
File metadata and controls
79 lines (66 loc) · 1.68 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
/*
* Problem Statement:
* Write a program to print the intersected numbers in two given matrices.
* 18)-الأعداد المتقاطعة في المصفوفات :
*/
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
#include <iomanip>
using namespace std;
int ReadNumber(string message)
{
int Number;
cout << message;
cin >> Number;
return Number;
}
void PrintMatrix(int arr[3][3], short Rows, short Cols)
{
for (int i = 0; i < Rows; i++)
{
for (int j = 0; j < Cols; j++)
{
cout << setw(3) << arr[i][j] << " ";
// printf("%0*d ", 2, arr[i][j]);
}
cout << endl;
}
}
bool IsNumberExistInMatrix(int Matrix[3][3], int Number, short Rows, short Cols)
{
for (short i = 0; i < Rows; i++)
{
for (short j = 0; j < Cols; j++)
{
if (Matrix[i][j] == Number)
return true;
}
}
return false;
}
void PrintIntersectedNumbersInMatrix(int arr1[3][3], int arr2[3][3], short Rows, short Cols)
{
int Number = 0;
for (short i = 0; i < Rows; i++)
{
for (short j = 0; j < Cols; j++)
{
Number = arr1[i][j];
if (IsNumberExistInMatrix(arr2, Number, Rows, Cols))
cout << setw(3) << Number << " ";
}
}
}
int main()
{
int Matrix1[3][3] = {{10, 1, 12}, {0, 9, 1}, {0, 9, 9}};
int Matrix2[3][3] = {{10, 11, 2}, {30, 4, 1}, {21, 9, 40}};
cout << "Matrix1: \n";
PrintMatrix(Matrix1, 3, 3);
cout << "\nMatrix2: \n";
PrintMatrix(Matrix2, 3, 3);
cout << "\nIntersected Numbers are :\n";
PrintIntersectedNumbersInMatrix(Matrix1, Matrix2, 3, 3);
}