I have to write a program which would compare two arrays and then displays the elements which are same in two arrays. I have written this program but i am not getting the right result. Kindly help me!
#include <iostream.h>
#include <conio.h>
int main()
{
int i,j,m,k[3],count=0;
int array[3];
cout<<"please enter the elements of first array"<<endl;
for (i=0; i < 3; i++)
{
cin>>array[i];
}
cout<<"please enter the elements of second array"<<endl;
for ( j=0; j<3; j++)
{
cin>>array[j];
}
#include <iostream.h>
#include <conio.h>
int main()
{
int i,j,m,k[3],count=0;
int array[3];
int array2[3];
int sameCount = 0;
cout<<"please enter the elements of first array"<<endl;
for (i=0; i < 3; i++)
{
cin>>array[i];
}
cout<<"please enter the elements of second array"<<endl;
for ( j=0; j<3; j++)
{
cin>>array[i];
cin>>array2[j];
}
for (i=0;i<3; i++)
{
for(j=0; j<3; j++)
{
for(m=0; m<3; m++)
{
if(array[i] == array[j])if(array[m] == array2[m])
{
k[m] = array[i];
++sameCount;
}
}
}
}
for(m=0; m<3; m++)
{
cout<<"the number of same values is"<<k[m]<<endl;
cout<<"the number of same values is"<<sameCount<<endl;
}
}
but that just gives the number of same values... can we display the same elements aswell? p.s i m a business student... i do this just for fun so dont mind the silly mistakes :D