c 2b 2b two array find same values

Solutions on MaxInterview for c 2b 2b two array find same values by the best coders in the world

showing results for - "c 2b 2b two array find same values"
Isabel
30 Nov 2020
1#include <iostream>
2#include <cstdlib>
3#include <conio.h>
4
5
6using namespace std;
7int main() 
8{
9int p[4] ,p1[4], num = 0 , p2[] = {};
10cout<<"Enter 4 numbers of the first array ";
11for(int a=0;a<4;a++){
12	cin>>p[a];
13}
14
15system("CLS");
16cout<<"Enter 4 numbers of the second array: ";
17for(int a=0;a<4;a++){
18	cin>>p1[a];
19}
20
21system("CLS");
22
23
24for(int i = 0 ; i < 4; ++i) {
25for (int j = 0 ; j < 4; ++j) {
26	if(p[i]==p1[j]) {
27		p2[num++] = p[j];
28}
29}
30}
31
32	cout<<"The number of common elements"<<num<<endl;
33	cout<<"These are the common numbers: ";
34	for (int k=0;k<num;k++){
35		cout<<p2[k]<<" ";
36	}
37	getch();
38	return 0;
39	
40}