Professional Documents
Culture Documents
(KCS353)
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,
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
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
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 :