Intersection

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,i,j,f=1;
    cout<<"Enter the size of first array :";
    cin>>x;
    cout<<"Enter the size of second array :";
    cin>>y;
    int a[x], b[y];
    cout<<"Enter the elements of first array :";
    for(i=0;i<x;i++)
    cin>>a[i];
    cout<<"Enter the elements of second array :";
    for(i=0;i<y;i++)
    cin>>b[i];
    for(i=0;i<x;i++)
    for(j=0;j<y;j++)
    if(a[i]==b[j])
    {cout<<a[i]<<" ";f=0;}
    if(f==1)
        cout<<"NO common elements !";
}

Comments

Popular posts from this blog

First_Come_First_Serve CPU Scheduling

Reversing stack Method 2 !! (One Helper Stack only)

Populating Next Right Pointers in Each Node in O(1) space (without queue and level order)

Calculate factorial of large numbers !! (Using Arrays)

Multiplication of large numbers (Given in string format)

Left View of Binary Tree (Method 1 using recursion)

Check Bracket Sequence

Image Multiplication

Boundary Traversal of binary tree

BST to greater sum tree