Answers for "c++ two array find same values"

C++
0

c++ two array find same values

#include <iostream>
#include <cstdlib>
#include <conio.h>


using namespace std;
int main() 
{
int p[4] ,p1[4], num = 0 , p2[] = {};
cout<<"Enter 4 numbers of the first array ";
for(int a=0;a<4;a++){
	cin>>p[a];
}

system("CLS");
cout<<"Enter 4 numbers of the second array: ";
for(int a=0;a<4;a++){
	cin>>p1[a];
}

system("CLS");


for(int i = 0 ; i < 4; ++i) {
for (int j = 0 ; j < 4; ++j) {
	if(p[i]==p1[j]) {
		p2[num++] = p[j];
}
}
}

	cout<<"The number of common elements"<<num<<endl;
	cout<<"These are the common numbers: ";
	for (int k=0;k<num;k++){
		cout<<p2[k]<<" ";
	}
	getch();
	return 0;
	
}
Posted by: Guest on April-02-2021

Code answers related to "c++ two array find same values"

Browse Popular Code Answers by Language