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];
}
相关阅读
Windows下C++开发有前途么?怎么检测一个文件占用的实际物理媒介地址?求本书请教个static_cast vs reinterpret_cast的问题。C++中如何数据文件一起build进exe文件中?全球著名品酒俱乐部,只需$69即可购买12瓶高档葡萄酒送高档开瓶器5/30-中国人北美甲骨文用户组IT新手入门第五讲 (转载)再问个python的问题,GUI方面的access function static variableD3這server到底有啥難度?這麼不stable?? (转载)什么时候该用什么sort算法64BIT 软件开发怎么提高技术水平?在破解的iphone上,如何编程?RUBY On Rails 如何快速入门这里的牛人很多,都读过标准吗非科班出身的想做程序员,考一些证是否有助于找到工作。 (转载)wiki上关于map的这段程序为什么不work?用C++的写的numerical or optimization solver library菜鸟问题:写一个小测试软件