a*g
2 楼
/* http://www.ccodechamp.com/c-program-of-set-operations-in-maths/ */
#include
#include
#define MAX 30
void create(int set[]);
void print(int set[]);
void Union(int set1[],int set2[],int set3[]);
void intersection(int set1[],int set2[],int set4[]);
int member(int set[],int x);
int main()
{ int set1[MAX],set2[MAX],set3[MAX];
int x,op;
set1[0]=set2[0]=set3[0]=0;
printf("-------------------------------------------------------------\n");
printf("----------------made by C code champ ------------------------\n");
printf("-------------------------------------------------------------\n");
printf("\n\n\tMENU BASED C PROGRAM OF SET OPERATIONS \n");
do
{
printf("\n1)Create two sets.");
printf("\n2)Print the set.");
printf("\n3)Union of two sets.");
printf("\n4)Intersection of two sets A intesection B.");
printf("\n5)Difference between two sets A - B");
printf("\n6)Symmetrec Difference between two sets i.e (A-B)U(B-A).");
printf("\n7)Exit from program\n\n");
printf("\nEnter Your Choice : ");
scanf("%d",&op);
printf("\n\n");
switch(op)
{
case 1: printf("\nCreate Set A: ");
create(set1);
printf("\nCreate Set B: ");
create(set2);
break;
case 2: printf("\nSet A:\n");
print(set1);
printf("\n\nSet B:\n");
print(set2);
break;
case 3: Union(set1,set2,set3);
print(set3);
break;
case 4: intersection(set1,set2,set3);
print(set3);
break;
case 5: difference(set1,set2,set3);
print(set3);
break;
case 6: symmetric(set1,set2,set3);
print(set3);
break;
case 7: break;
default:
printf("\nPlease Enter a valid choice\n");
break;
}
printf("\n\nPress a key to continue......\n\n");
getch();
}while(op!=7);
}
void create(int set[])
{ int n,i,x;
set[0]=0;
printf("\nNo. of elements in the set : ");
scanf("%d",&n);
printf("\nEnter set elements : \n");
for(i=1;i<=n;i++)
scanf("%d",&set[i]);
set[0]=n;
}
void print(int set[])
{
int i,n;
n=set[0];
printf("\nMembers of the set :--> ");
for(i=1;i<=n;i++)
printf("%d ",set[i]);
}
void Union(int set1[],int set2[],int set3[])
{ int i,n;
set3[0]=0;
n=set1[0];
for(i=0;i<=n;i++)
set3[i]=set1[i];
n=set2[0];
for(i=1;i<=n;i++)
if(!member(set3,set2[i]))
set3[++set3[0]]=set2[i];
}
int member(int set[],int x)
{
int i,n;
n=set[0];
for(i=1;i<=n;i++)
if(x==set[i])
return(1);
return(0);
}
void intersection(int set1[],int set2[],int set3[])
{
int i,n;
set3[0]=0;
n=set1[0];
for(i=1;i<=n;i++)
if(member(set2,set1[i]))
set3[++set3[0]]=set1[i];
}
#include
#include
#define MAX 30
void create(int set[]);
void print(int set[]);
void Union(int set1[],int set2[],int set3[]);
void intersection(int set1[],int set2[],int set4[]);
int member(int set[],int x);
int main()
{ int set1[MAX],set2[MAX],set3[MAX];
int x,op;
set1[0]=set2[0]=set3[0]=0;
printf("-------------------------------------------------------------\n");
printf("----------------made by C code champ ------------------------\n");
printf("-------------------------------------------------------------\n");
printf("\n\n\tMENU BASED C PROGRAM OF SET OPERATIONS \n");
do
{
printf("\n1)Create two sets.");
printf("\n2)Print the set.");
printf("\n3)Union of two sets.");
printf("\n4)Intersection of two sets A intesection B.");
printf("\n5)Difference between two sets A - B");
printf("\n6)Symmetrec Difference between two sets i.e (A-B)U(B-A).");
printf("\n7)Exit from program\n\n");
printf("\nEnter Your Choice : ");
scanf("%d",&op);
printf("\n\n");
switch(op)
{
case 1: printf("\nCreate Set A: ");
create(set1);
printf("\nCreate Set B: ");
create(set2);
break;
case 2: printf("\nSet A:\n");
print(set1);
printf("\n\nSet B:\n");
print(set2);
break;
case 3: Union(set1,set2,set3);
print(set3);
break;
case 4: intersection(set1,set2,set3);
print(set3);
break;
case 5: difference(set1,set2,set3);
print(set3);
break;
case 6: symmetric(set1,set2,set3);
print(set3);
break;
case 7: break;
default:
printf("\nPlease Enter a valid choice\n");
break;
}
printf("\n\nPress a key to continue......\n\n");
getch();
}while(op!=7);
}
void create(int set[])
{ int n,i,x;
set[0]=0;
printf("\nNo. of elements in the set : ");
scanf("%d",&n);
printf("\nEnter set elements : \n");
for(i=1;i<=n;i++)
scanf("%d",&set[i]);
set[0]=n;
}
void print(int set[])
{
int i,n;
n=set[0];
printf("\nMembers of the set :--> ");
for(i=1;i<=n;i++)
printf("%d ",set[i]);
}
void Union(int set1[],int set2[],int set3[])
{ int i,n;
set3[0]=0;
n=set1[0];
for(i=0;i<=n;i++)
set3[i]=set1[i];
n=set2[0];
for(i=1;i<=n;i++)
if(!member(set3,set2[i]))
set3[++set3[0]]=set2[i];
}
int member(int set[],int x)
{
int i,n;
n=set[0];
for(i=1;i<=n;i++)
if(x==set[i])
return(1);
return(0);
}
void intersection(int set1[],int set2[],int set3[])
{
int i,n;
set3[0]=0;
n=set1[0];
for(i=1;i<=n;i++)
if(member(set2,set1[i]))
set3[++set3[0]]=set1[i];
}
相关阅读
老年C 程序员求建议操他妈谷歌gmail脑袋进屎了?100伪币悬赏:CNN这个东西本质上处理不了形变[bssd]这段代码有什么问题希望拜gvest为师说到政治,问个跟高级别的老印合作的事为什么程序员是一个伟大的职业? (转载)warning: returning address of local variable or temporary[bssd]科技对社会在国内正面作用还是非常大求Python for Data Analysis, 2nd Editionset operation in c有多少人相信无人车?guvest老哥不好意思了应该读phd吗?问一道狗狗网管面试题 (转载)[bssd]使用clojure的一些个人体会Faster-RCNN用一个window大小就能预测box折腾别的,不如先写个email分析统计系统请教一个windows下面的编程问题不管大家怎么评论,wangyin的这篇说的挺有道理的