You are on page 1of 10

DSTL LAB

(KCS353)

Submitted To: Submitted By:


Mr. Rajiv Ranjan Utkarsh Verma(200192100318)

Department of Computer Science & Engineering


G.L. Bajaj Institute of Technology and Management
Greater Noida - 201306
S.No. Name of Experiment Date of Date of Signature of Remarks
Experiment Submission Faculty with
Date

1. Write a program in C to create


two sets and perform the
Union operation on sets.

2. Write a program in C to create


two sets and perform the
Intersection operation on sets.

3. Write a program in C to create


two sets and perform the
Difference operation on sets.

4. Write a program in C to create


two sets and perform the
Symmetric Difference operation.

5. Write a program in C to perform


the Power Set operation on a set.

6. Write a program in C to Display


the Boolean Truth Table for
AND, OR , NOT .

7. Write a C Program to find


Cartesian Product of two sets

8. Write a program in C for


minimum cost spanning tree.

9. Write a program in C for finding


shortest path in a Graph
EXPERIMENT-4
OBJECTIVE- Write a program in C to create two
sets and perform symmetric difference operation
on sets.
SOFTWARE USED- Code blocks

THEORY- The symmetric difference of two sets, also known as the


disjunctive union, is the set of elements which are in either of the sets,
but not in their intersection.
For example, the symmetric difference of the sets 1,2,3 and 3,4 is 1,2,4.

PROGRAM CODE-

#include <stdio.h>
int main(){
int a[5],b[5],c[10],d[10],e[20],i,j,k=0,p=0,m,n,n1,n2,t=0;
printf("Enter size of Set A and Set B:: ");
scanf("%d%d",&n1,&n2);
printf("\nEnter elements of set A:: ");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
printf("\nEnter elements of set B:: ");
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])
k++;
}
if(k==0){
c[p]=a[i];
p++;
}
k=0;
}
m=p;
printf("\nSet A - Set B : ");
for(i=0;i<p;i++)
printf("%d ",c[i]);
p=k=0;
for(i=0;i<n2;i++) {
for(j=0;j<n1;j++){
if(b[i]==a[j])
k++;
}
if(k==0){
d[p]=b[i];
p++;
}
k=0;
}
n=p;
printf("\nSet B - Set A : ");
for(i=0;i<p;i++)
printf("%d ",d[i]);
for(i=0;i<m;i++) //UNION OF C AND D
e[i]=c[i];
for(j=0;j<n;j++) {
p=0;
for(k=0;k<m;k++){
if(d[j]==c[k])
p++;
}
if(p==0){
e[i]=d[j];
i++;
t++;
}
}
printf("\nSYMMETRIC DIFFERENCE IS:: ");
for(j=0;j<m+t;j++)
printf("%d ",e[j]);
return 0;
}

Output :
EXPERIMENT-5
OBJECTIVE- Write a program in C to create two
sets and perform power set operation on the set.
SOFTWARE USED- Code blocks

THEORY- The power set (or powerset) of a set S is the set of all
subsets of
S, including the empty set and S itself. For example,

powerset of A= {1,2} is PA = {{}, {1}, {2}, {1,2}}.

PROGRAM CODE-
#include<stdio.h>
#include<math.h>
long int bin(int);
int main()
{
int a[50],s1,a1,i,c=0;
long int b;
printf("\nEnter size of set A : ");
scanf("%d",&s1);
printf("\nEnter the elements of set A : ");
for(i=0;i<s1;i++){
scanf("%d",&a[i]);
}
printf("\nPOWER SET OF THE GIVEN SET is ::\n{}\n");
for(i=1;i<pow(2,s1);i++)
{
b=bin(i);
while(b!=0)
{
a1=b%10;
if(a1==1)
printf("%d ",a[c]);
c++;
b=b/10;
}
c=0;
printf("\n");}
}
long int bin(int n) {
int c=0,a,d=0;
while(n!=0)
{
a=n%2;
d=d+a*pow(10,c);
c++; n=n/2;
}
return d; }

Output:
EXPERIMENT-6
OBJECTIVE- Write a program in C to display the
TRUTH TABLE for AND,OR and NOT
operations.
SOFTWARE USED- Code blocks

THEORY- The table used to represent the boolean expression of a


logic gate function is commonly called a Truth Table. A logic gate truth
table shows each possible input combination to the gate or circuit with
the resultant output depending upon the combination of these input(s).

PROGRAM CODE-
#include<stdio.h>
void AND(int a[],int b[]){
int c[4],i;
for(i=0;i<4;i++)
c[i]=a[i]&&b[i];
printf("\nx y z \n");
for(i=0;i<4;i++)
printf("%d %d %d\n",a[i],b[i],c[i]);
}
void OR(int a[],int b[]){
int c[4],i;
for(i=0;i<4;i++)
c[i]=a[i]||b[i];
printf("\nx y z \n");
for(i=0;i<4;i++)
printf("%d %d %d\n",a[i],b[i],c[i]);
}
void NOT(int a[],int b[]){
int c[4],d[4],i;
for(i=0;i<4;i++)
c[i]=!a[i];
for(i=0;i<4;i++)
d[i]=!b[i];
printf("\nx x' y y' \n");
for(i=0;i<4;i++)
printf("\n PRESS 1 FOR AND OPERATION");
printf("\n PRESS 2 FOR OR OPERATION");
printf("\n PRESS 3 FOR NOT OPERATION");
printf("\nEnter you choice::");
scanf("%d",&ch);
switch(ch){
case 1:AND(x,y);
break;
case 2:OR(x,y);
break;
case 3:NOT(x,y);
break;
default:printf("\nWRONG CHOICE");
}
printf("\nDo you want choices again(1 for yes and 0 for no)::");
scanf("%d",&choice);
}
}printf("%d %d %d %d\n",a[i],c[i],b[i],d[i]);
}
int main(){
int x[]={0,0,1,1};
int y[]={0,1,0,1};
int ch,choice=1;
while(choice){
printf("\n----MENU----");
printf("\n PRESS 1 FOR AND OPERATION");
printf("\n PRESS 2 FOR OR OPERATION");
printf("\n PRESS 3 FOR NOT OPERATION");
printf("\nEnter you choice::");
scanf("%d",&ch);
switch(ch){
case 1:AND(x,y);
break;
case 2:OR(x,y);
break;
case 3:NOT(x,y);
break;
default:printf("\nWRONG CHOICE");
}
printf("\nDo you want choices again(1 for yes and 0 for no)::");
scanf("%d",&choice);
}
}

Output :
EXPERIMENT-7
OBJECTIVE- Write a program in C to find
Cartesian Product of two sets.
SOFTWARE USED- Code blocks

THEORY- The Cartesian product of two sets A and B, denoted A


× B, is the set of all possible ordered pairs where the elements of A are
first and the elements of B are second. Example: A × = since no
ordered pairs can be formed when one of the sets is empty.

PROGRAM CODE-
#include<stdio.h>
int main(){
int a[10],b[10],n1,n2,i,j;
printf("\nEnter size of set A and set B:: ");
scanf("%d%d",&n1,&n2);
printf("\nEnter elements of set A:: ");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
printf("\nEnter elements of set B:: ");
for(i=0;i<n2;i++)
scanf("%d",&b[i]);
printf("\nCartesian product of set A and set B:: ");
printf("\n{");
for(i=0;i<n1;i++){
for(j=0;j<n2;j++){
printf("(%d,%d) ",a[i],b[j]);
}
}
printf("}");
return 0;
}
Output :

You might also like