Friday, 20 January 2012

check whether a set is a subset of other.............


#include<stdio.h>
#include<conio.h>

void main()
{
int u[50],s[50],n,m,i,j,count=0;
clrscr();
printf("\nENTER THE SIZE OF UNIVERSAL SET\n");
scanf("%d",&n);
printf("ENTER THE n ELEMENTS OF UNIVERSAL SET\n");
for(i=0;i<n;i++)
scanf("%d",&u[i]);
printf("\nENTER THE SIZE OF SET TO BE FOUND WHETHER IT IS A SUBSET OF UNIVERSAL SET\n(LESS THAN OR EQUAL TO THE SIZE OF UNIVERSAL SET)\n");
scanf("%d",&m);
printf("ENTER THE ELEMENTS OF THE SET\n");
for(i=0;i<m;i++)
scanf("%d",&s[i]);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(s[i]==u[j])
{
count++;
}
}
}
if(count==m)
printf("GIVEN SET IS A SUBSET OF UNIVERSAL SET\n");
else
printf("GIVEN SET IS NOT A SUBSET OF UNIVERSAL SET\n");
getch();
}                                                                    

No comments:

Post a Comment