/* =====================================================================================
* *
* * Filename: setoperation.c
* * Created: Sunday 11 January 2015 09:10:17 IST
* * Compiler: gcc
* * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * Organization: SCIS,University of Hyderabad
* *
* * =====================================================================================*/
#include<stdio.h>
#include<stdlib.h>
void Union(int set1[10],int set2[10],int m,int n);
void Intersection(int set1[10],int set2[10],int m,int n);
void Difference(int set1[10],int set2[10],int m, int n);
void RelativeComplement(int set1[10],int set2[10],int m, int n);
void main()
{
int a[10],b[10],m,n,i,j;
int ch;
printf("\nEnter the number of elements in first set:\n");
scanf("%d",&m);
printf("\nEnter the elements:\n");
for(i=0; i<m; i++)
{
scanf("%d",&a[i]);
}
printf("\nElement of First set:\n\n");
for(i=0;i<m;i++)
{
printf("%d\t",a[i]);
}
printf("\nEnter the number of elements in second set:\n");
scanf("%d",&n);
printf("\nEnter the elements:\n");
for(i=0; i<n; i++)
{
scanf("%d",&b[i]);
}
printf("\nElement of second set\n\n");
for(i=0; i<n; i++)
{
printf("%d\t",b[i]);
}
for(;;)
{
printf("\n\n*****What do you wanna do..??*****\n");
printf("...Menu...\n1.Union\n2.Intersection\n3.Difference\n4.Complement");
printf("\n5.exit");
printf("\nEnter your choice:\n");
scanf("%d",&ch);
switch(ch) {
case 1:
Union(a,b,m,n);
break;
case 2:
Intersection(a,b,m,n);
break;
case 3:
Difference(a,b,m,n);
break;
case 4:
RelativeComplement(a,b,m,n);
break;
case 5:
exit(1);
}
}
}
void Union(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
c[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<m;j++)
{
if(b[i]==c[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=b[i];
k++;
}
}
printf("\nCalculatting...");
printf("\nElement of UNION set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
void Intersection(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==1)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nResultant set is null set!\n");
}else{
printf("\nElement of resultant set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
}
void Difference(int a[10],int b[10],int m,int n)
{
int c[10],i,j,k=0,flag=0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nResultant set is null set!\n");
}
else
{
printf("\nElements of Difference set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
}
void RelativeComplement(int a[10],int b[10],int m,int n)
{
int c[10],d[10],i,j,k=0,l=0,flag=0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nThe Relative Complement of set2 in set1 is null set!\n");
}
else
{
printf("\nThe RelativeComplement of set2 in set1:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
printf("\n");
}
* *
* * Filename: setoperation.c
* * Created: Sunday 11 January 2015 09:10:17 IST
* * Compiler: gcc
* * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * Organization: SCIS,University of Hyderabad
* *
* * =====================================================================================*/
#include<stdio.h>
#include<stdlib.h>
void Union(int set1[10],int set2[10],int m,int n);
void Intersection(int set1[10],int set2[10],int m,int n);
void Difference(int set1[10],int set2[10],int m, int n);
void RelativeComplement(int set1[10],int set2[10],int m, int n);
void main()
{
int a[10],b[10],m,n,i,j;
int ch;
printf("\nEnter the number of elements in first set:\n");
scanf("%d",&m);
printf("\nEnter the elements:\n");
for(i=0; i<m; i++)
{
scanf("%d",&a[i]);
}
printf("\nElement of First set:\n\n");
for(i=0;i<m;i++)
{
printf("%d\t",a[i]);
}
printf("\nEnter the number of elements in second set:\n");
scanf("%d",&n);
printf("\nEnter the elements:\n");
for(i=0; i<n; i++)
{
scanf("%d",&b[i]);
}
printf("\nElement of second set\n\n");
for(i=0; i<n; i++)
{
printf("%d\t",b[i]);
}
for(;;)
{
printf("\n\n*****What do you wanna do..??*****\n");
printf("...Menu...\n1.Union\n2.Intersection\n3.Difference\n4.Complement");
printf("\n5.exit");
printf("\nEnter your choice:\n");
scanf("%d",&ch);
switch(ch) {
case 1:
Union(a,b,m,n);
break;
case 2:
Intersection(a,b,m,n);
break;
case 3:
Difference(a,b,m,n);
break;
case 4:
RelativeComplement(a,b,m,n);
break;
case 5:
exit(1);
}
}
}
void Union(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
c[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<m;j++)
{
if(b[i]==c[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=b[i];
k++;
}
}
printf("\nCalculatting...");
printf("\nElement of UNION set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
void Intersection(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==1)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nResultant set is null set!\n");
}else{
printf("\nElement of resultant set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
}
void Difference(int a[10],int b[10],int m,int n)
{
int c[10],i,j,k=0,flag=0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nResultant set is null set!\n");
}
else
{
printf("\nElements of Difference set:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
}
void RelativeComplement(int a[10],int b[10],int m,int n)
{
int c[10],d[10],i,j,k=0,l=0,flag=0;
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=a[i];
k++;
}
}
printf("\nCalculatting...");
if(k==0)
{
printf("\n\nThe Relative Complement of set2 in set1 is null set!\n");
}
else
{
printf("\nThe RelativeComplement of set2 in set1:\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
printf("\n");
}
No comments:
Post a Comment