mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-14 19:00:15 +08:00
formatting filenames d7af6fdc8c
This commit is contained in:
31
operations_on_datastructures/intersection_of_2_arrays.cpp
Normal file
31
operations_on_datastructures/intersection_of_2_arrays.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
int i, j, m, n;
|
||||
cout << "Enter size of array 1:";
|
||||
cin >> m;
|
||||
cout << "Enter size of array 2:";
|
||||
cin >> n;
|
||||
int a[m];
|
||||
int b[n];
|
||||
cout << "Enter elements of array 1:";
|
||||
for (i = 0; i < m; i++)
|
||||
cin >> a[i];
|
||||
for (i = 0; i < n; i++)
|
||||
cin >> b[i];
|
||||
i = 0;
|
||||
j = 0;
|
||||
while ((i < m) && (j < n))
|
||||
{
|
||||
if (a[i] < b[j])
|
||||
i++;
|
||||
else if (a[i] > b[j])
|
||||
j++;
|
||||
else
|
||||
{
|
||||
cout << a[i++] << " ";
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user