Assign 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Discrete structures and Logic Lab(KCS-353)

EXPERIMENT No. 02

AIM: To perform Intersection operation on sets

DESCRIPTION: The intersection of sets A and B is the set of all elements which
are common to both A and B.

CODE:

#include<stdio.h>
int main()
{
int a[100],b[100],c[100],n1,n2,n,k=0,i,j;
printf("Enter number of element of set A\n");
scanf("%d",&n1);
printf("Enter elements of set A\n");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
printf("Enter number of element of set B\n");
scanf("%d",&n2);
printf("Enter elements of set B\n");
for( i=0;i<n2;i++)
scanf("%d",&b[i]);
for(i=0;i<n1;i++)
{
for(j=0;j<n2;j++)
{
if(a[i]=b[j])
{
c[k]=a[i];
k++;
}
}
}
printf("Intersection is: \n");
for(i=0;i<k;i++)
{
printf("%d\t",c[i]);
return 0;
}
}

DIVAKAR 2100910130045 IT1 A(2)


Discrete structures and Logic Lab(KCS-353)

Output:

Enter number of element of set A


3
Enter elements of set A
1
3
5
Enter number of element of set B
3
Enter elements of set B
1
4
5
Intersection is:
1 5

DIVAKAR 2100910130045 IT1 A(2)

You might also like