include iostream include Windows include time define BORDER_LOW -2 def

 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
#include <iostream>
#include <Windows.h>
#include <time.h>
#define BORDER_LOW -2
#define BORDER_HIGH 2
using namespace std;
void createMatrix(int **Matrix, int rows, int columns) {
int i, j;
for (i = 0; i < rows; i++) {
cout<<endl;
for (j = 0; j < columns; j++) {
Matrix[i][j] = rand() % (BORDER_HIGH + 1 - BORDER_LOW) + BORDER_LOW;
cout<<Matrix[i][j]<<"\t";
}
}
}
int in(int num, int* arr, int s)
{
for (int i = 0; i < s; i++)
if (arr[i]==num)
return i;
return -1;
}
int main() {
srand(time(NULL));
int i, j;
int NUM_ROWS, NUM_COLUMNS;
cout<<"Enter the number of rows: "<<endl;
cin>>NUM_ROWS;
cout<<"Enter the number of columns "<<endl;
cin>>NUM_COLUMNS;
cout<<endl;
int** Matrix=new int *[NUM_ROWS];
for (i=0; i<NUM_ROWS; i++)
Matrix[i]=new int [NUM_COLUMNS];
createMatrix(Matrix, NUM_ROWS, NUM_COLUMNS);
int *a = new int [NUM_COLUMNS];
int l = 0,exist,pos;
/////////////
for (i = 0; i < NUM_COLUMNS; i++)
{
if (in(Matrix[0][i],a,l)==-1)
a[l++]=Matrix[0][i];
}
for (i = 1; i < NUM_ROWS; i++)
{
cout<<endl;
cout<<i<<" iteration: ";
for (int o = 0; o < l; o++)
cout<<a[o]<<"\t";
for (j=0;j<l;j++)
{
pos = in(a[j],Matrix[i],NUM_COLUMNS);
if (pos==-1)
{
for (int k=j;k<l-1;k++)
a[k]=a[k+1];
l--;
j--;
}
}
}
cout<<endl;
cout<<endl;
for (int i = 0; i < l; i++)
cout<<a[i]<<"\t";
cout<<endl;
system("pause");
return 0;
}