用c语言写两个程序,1,集合的交并差运算.2,计算关系的闭包(3种)不要求功能非常完备,能实现最基本的就行,采纳了把我所
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/05 14:39:40
用c语言写两个程序,1,集合的交并差运算.2,计算关系的闭包(3种)不要求功能非常完备,能实现最基本的就行,采纳了把我所有的都给你,四百分
![用c语言写两个程序,1,集合的交并差运算.2,计算关系的闭包(3种)不要求功能非常完备,能实现最基本的就行,采纳了把我所](/uploads/image/z/4661261-53-1.jpg?t=%E7%94%A8c%E8%AF%AD%E8%A8%80%E5%86%99%E4%B8%A4%E4%B8%AA%E7%A8%8B%E5%BA%8F%2C1%2C%E9%9B%86%E5%90%88%E7%9A%84%E4%BA%A4%E5%B9%B6%E5%B7%AE%E8%BF%90%E7%AE%97.2%2C%E8%AE%A1%E7%AE%97%E5%85%B3%E7%B3%BB%E7%9A%84%E9%97%AD%E5%8C%85%EF%BC%883%E7%A7%8D%EF%BC%89%E4%B8%8D%E8%A6%81%E6%B1%82%E5%8A%9F%E8%83%BD%E9%9D%9E%E5%B8%B8%E5%AE%8C%E5%A4%87%2C%E8%83%BD%E5%AE%9E%E7%8E%B0%E6%9C%80%E5%9F%BA%E6%9C%AC%E7%9A%84%E5%B0%B1%E8%A1%8C%2C%E9%87%87%E7%BA%B3%E4%BA%86%E6%8A%8A%E6%88%91%E6%89%80)
第一个程序
集合的交并差运算
#include
#include
typedef struct pointer{
char dat;
struct pointer *link;
} pointer;
void readdata(pointer *head){ //读集合
pointer *p;
char tmp;
printf("input data ('0' for end):");
scanf("%c",&tmp);
while(tmp!='0')
{
if((tmp'z'))
{
printf("输入错误!必须为小写字母!\n");
return;
}
p=(pointer *)malloc(sizeof(struct pointer));
p->dat=tmp;
p->link=head->link;
head->link=p;
scanf("%c",&tmp);
}
}
void disp(pointer *head){ //显示集合数据
pointer *p;
p=head->link;
while(p!=NULL)
{
printf("%c ",p->dat);
p=p->link;
}
printf("\n");
}
void bing(pointer *head1,pointer *head2,pointer *head3){ //计算集合1与集合2的并
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p1->dat;
p3->link=head3->link;
head3->link=p3;
p1=p1->link;
}
p2=head2->link;
while(p2!=NULL)
{
p1=head1->link;
while((p1!=NULL)&&(p1->dat!=p2->dat))
p1=p1->link;
if(p1==NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p2->dat;
p3->link=head3->link;
head3->link=p3;
}
p2=p2->link;
}
}
void jiao(pointer *head1,pointer *head2,pointer *head3){ //计算集合1与集合2的交
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p2=head2->link;
while((p2!=NULL)&&(p2->dat!=p1->dat))
p2=p2->link;
if((p2!=NULL)&&(p2->dat=p1->dat))
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p1->dat;
p3->link=head3->link;
head3->link=p3;
}
p1=p1->link;
}
}
void cha(pointer *head1,pointer *head2,pointer *head3){ //计算集合1与集合2的差
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p2=head2->link;
while((p2!=NULL)&&(p2->dat!=p1->dat))
p2=p2->link;
if(p2==NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p1->dat;
p3->link=head3->link;
head3->link=p3;
}
p1=p1->link;
}
}
main(){
pointer *head1,*head2,*head3;
head1=(pointer *)malloc(sizeof(struct pointer));
head1->link=NULL;
head2=(pointer *)malloc(sizeof(struct pointer));
head2->link=NULL;
head3=(pointer *)malloc(sizeof(struct pointer));
head3->link=NULL;
printf("输入集合1:\n");
readdata(head1);
printf("输入集合2:\n");
readdata(head2);
printf("集合1为:\n");
disp(head1);
printf("集合2为:\n");
disp(head2);
printf("集合1与集合2的并为:\n");
bing(head1,head2,head3);
disp(head3);
head3->link=NULL;
printf("集合1与集合2的交为:\n");
jiao(head1,head2,head3);
disp(head3);
head3->link=NULL;
printf("集合1与集合2的差为:\n");
cha(head1,head2,head3);
disp(head3);
}
测试用例为(0表示集合输入结束):
fdsa0
savc0
第二个程序
计算关系的闭包(3种)
#include
void output(int s[][100]);
void zifan(int s2[][100]);
void duichen(int s2[][100]);
void chuandi2(int s2[][100]);
void chuandi1(int s2[][100]);
void aa();
int s[100][100],z;
int d,n ,i,j;
int main(){aa();return 0;}
void aa()
{
printf("请输入矩阵的行数(必须小于10)\n ");
scanf("%d",&n);
printf("请输入矩阵的列数(必须小于10)\n ");
scanf("%d",&d);
printf("请输入关系矩阵\n");
for(i=0;i
再问: 谢谢,待会验证,然后采纳
再问: 谢谢,待会验证,然后采纳
再问: 可以的,竟然最高只能200分,先采纳了,还有200你看下怎么给你,
再答: 发不了
再问: 要不再提一个你来答,我采纳
再问: 要不再提一个你来答,我采纳
再问: 大神,刚提了一个问题,没有上次那么麻烦,帮我看一个写好的代码,有点问题
集合的交并差运算
#include
#include
typedef struct pointer{
char dat;
struct pointer *link;
} pointer;
void readdata(pointer *head){ //读集合
pointer *p;
char tmp;
printf("input data ('0' for end):");
scanf("%c",&tmp);
while(tmp!='0')
{
if((tmp'z'))
{
printf("输入错误!必须为小写字母!\n");
return;
}
p=(pointer *)malloc(sizeof(struct pointer));
p->dat=tmp;
p->link=head->link;
head->link=p;
scanf("%c",&tmp);
}
}
void disp(pointer *head){ //显示集合数据
pointer *p;
p=head->link;
while(p!=NULL)
{
printf("%c ",p->dat);
p=p->link;
}
printf("\n");
}
void bing(pointer *head1,pointer *head2,pointer *head3){ //计算集合1与集合2的并
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p1->dat;
p3->link=head3->link;
head3->link=p3;
p1=p1->link;
}
p2=head2->link;
while(p2!=NULL)
{
p1=head1->link;
while((p1!=NULL)&&(p1->dat!=p2->dat))
p1=p1->link;
if(p1==NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p2->dat;
p3->link=head3->link;
head3->link=p3;
}
p2=p2->link;
}
}
void jiao(pointer *head1,pointer *head2,pointer *head3){ //计算集合1与集合2的交
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p2=head2->link;
while((p2!=NULL)&&(p2->dat!=p1->dat))
p2=p2->link;
if((p2!=NULL)&&(p2->dat=p1->dat))
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p1->dat;
p3->link=head3->link;
head3->link=p3;
}
p1=p1->link;
}
}
void cha(pointer *head1,pointer *head2,pointer *head3){ //计算集合1与集合2的差
pointer *p1,*p2,*p3;
p1=head1->link;
while(p1!=NULL)
{
p2=head2->link;
while((p2!=NULL)&&(p2->dat!=p1->dat))
p2=p2->link;
if(p2==NULL)
{
p3=(pointer *)malloc(sizeof(struct pointer));
p3->dat=p1->dat;
p3->link=head3->link;
head3->link=p3;
}
p1=p1->link;
}
}
main(){
pointer *head1,*head2,*head3;
head1=(pointer *)malloc(sizeof(struct pointer));
head1->link=NULL;
head2=(pointer *)malloc(sizeof(struct pointer));
head2->link=NULL;
head3=(pointer *)malloc(sizeof(struct pointer));
head3->link=NULL;
printf("输入集合1:\n");
readdata(head1);
printf("输入集合2:\n");
readdata(head2);
printf("集合1为:\n");
disp(head1);
printf("集合2为:\n");
disp(head2);
printf("集合1与集合2的并为:\n");
bing(head1,head2,head3);
disp(head3);
head3->link=NULL;
printf("集合1与集合2的交为:\n");
jiao(head1,head2,head3);
disp(head3);
head3->link=NULL;
printf("集合1与集合2的差为:\n");
cha(head1,head2,head3);
disp(head3);
}
测试用例为(0表示集合输入结束):
fdsa0
savc0
第二个程序
计算关系的闭包(3种)
#include
void output(int s[][100]);
void zifan(int s2[][100]);
void duichen(int s2[][100]);
void chuandi2(int s2[][100]);
void chuandi1(int s2[][100]);
void aa();
int s[100][100],z;
int d,n ,i,j;
int main(){aa();return 0;}
void aa()
{
printf("请输入矩阵的行数(必须小于10)\n ");
scanf("%d",&n);
printf("请输入矩阵的列数(必须小于10)\n ");
scanf("%d",&d);
printf("请输入关系矩阵\n");
for(i=0;i
再问: 谢谢,待会验证,然后采纳
再问: 谢谢,待会验证,然后采纳
再问: 可以的,竟然最高只能200分,先采纳了,还有200你看下怎么给你,
再答: 发不了
再问: 要不再提一个你来答,我采纳
再问: 要不再提一个你来答,我采纳
再问: 大神,刚提了一个问题,没有上次那么麻烦,帮我看一个写好的代码,有点问题
用c语言写两个程序,1,集合的交并差运算.2,计算关系的闭包(3种)不要求功能非常完备,能实现最基本的就行,采纳了把我所
编写程序,实现两个集合的交运算(用C语言)
数据结构 用c语言写的 集合的并、交和差运算的程序
c语言:设一个函数,调用它时,每次实现不同的功能:(1)求两个数之和;(2)求两个数之差;(3)求
试用集合A、B、C的交并补运算表示集合D(详情见补充)
已知(集合的交并补的运算)
C语言抛硬币基本程序,不要高级语言,需要rand srand 的就行,
本人碰见一道C语言难题,利用C语言实现:求任意两个集合的交集、并集、差集,
pascal语言 编写一个算法实现两个集合的差运算
C语言,改一下程序,实现两个整数交换的功能,
用Java编程来实现两数的和、差、积、商、求余等运算.提示:在一个程序中实现所有功能,两个数的值从键盘
本人碰见一道C语言难题,寻大神帮助,利用C语言实现:求任意两个集合的交集、并集、差集,兄弟感激不尽