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];
}
相关阅读
Go lang不错。设计很干净,一天不到就能完全掌握,马上上手。比Java强netflix转向node.js,再弹go的扯淡性四九年加入国民党ML/AI...需要回调这哥们特别hilariousxgboost预测结果不一致怎么回事?Nvidia T4认知科学在人工智能的实际研发过程中有用吗?问卷调查类型数据deep learning可以上吗?马老师...除了神经网络,还有什么方法可以静态语言怎么存 values of different type into DictionariesIBM buying Red Hat?半懂不懂的reviewer真麻烦大佬们能不能评论一下本期关于AlphaZero的文章?wireless sensor network谁总结一下魏老师的专利能够干什么?老年软工转Devops張老師比楊振寧差的太遠了好想很多地方都在裁员?