当前位置:首页 » 编程语言 » c语言交

c语言交

发布时间: 2023-01-15 00:57:47

㈠ 谁知道计算机c语言中交和差的区别

intersect(交集)运算返回查询结果中相同的部分
minus(差)运算返回在第一个查询结果中与第二个查询结果不相同的那部分行记录

㈡ 用C语言编写一个集合的交,并和差运算的程序怎么写啊

/*第一,你的题意不明,我只能输入两个集合了【互异性由输入保证】*/
#include<stdio.h>
#include<string.h>
void main()
{
char temp[60]="",str1[30]="",str2[30]="",i,j,l1,l2,ch;
printf("STR1:");
gets(str1);
printf("STR2:");
gets(str2);
l1=strlen(str1);
l2=strlen(str2);
//交集
printf(" 交集: {");
for(i=0;i<l1;i++)
for(j=0;j<l2;j++)
if(str1[i]==str2[j]) printf("%c,",str1[i]);
printf("} ");

//并集 偷懒的算法: 合并->排序->删除相同
printf(" 并集: {");

/*合并*/sprintf(temp,"%s%s",str1,str2);
/*排序*/
for(i=0;i<l1+l2-1;i++)
for(j=i+1;j<l1+l2;j++)
if(temp[i]>temp[j])
{
char ch;
ch=temp[i];
temp[i]=temp[j];
temp[j]=ch;
}
/*删除相同字符*/
for(i=j=1;i<l1+l2;i++)
if(temp[i]!=temp[j-1]) temp[j++]=temp[i];
temp[j]=''
for(i=0;i<j;i++)
printf("%c,",temp[i]);
printf("} ");
//CuA
printf(" CuA: {");
for(ch='a'ch<='z'ch++)
{
for(i=0;i<l1;i++)
if(ch==str1[i]) goto NOT;
printf("%c,",ch);
NOT:if(0);
}
printf("} ");
//CuB
printf(" CuB: {");
for(ch='a'ch<='z'ch++)
{
for(i=0;i<l2;i++)
if(ch==str2[i]) goto NOT2;
printf("%c,",ch);
NOT2:if(0);
}
printf("} ");
}

㈢ 编写程序,实现两个集合的交运算(用C语言)

#include<stdio.h>
#include<string.h>
intjiaoji(intA[],intB[],inta,intb)
{
inti,j,t;
t=a;
for(i=0;i<a;i++)
for(j=0;j<b;j++)
{
if(A[i]==B[j])
{
A[t]=B[j];
t++;
}
}
for(i=0;i<t-a;i++)
{
A[i]=A[a+i];
}
returnt-a;
}
intmain()
{
intA[50],B[50],a,b,t;
printf("请输入A的元素个数: ");
scanf("%d",&a);
printf("请输入A的元素: ");
for(inti=0;i<a;i++)
scanf("%d",&A[i]);
printf("请输入B的元素个数: ");
scanf("%d",&b);
printf("请输入B的元素: ");
for(inti=0;i<b;i++)
scanf("%d",&B[i]);
t=jiaoji(A,B,a,b);
for(inti=0;i<t;i++)
printf("%d",A[i]);
return0;
}

㈣ c语言并,交,非程序的先后顺序是怎样的

非的优先级最高,并和交优先级相同

㈤ 数据结构 用c语言写的 集合的并、交和差运算的程序

可以用二个一维数组,
再用两个for循环来判断结果:交,并,差
在for循环中,用一个if来判断一下,是不是a[0]==b[j],只要有相等的,就令之放在c[0]
这就是交集!!

并集就好求吧,
只要令c[i]=a[i],再来一个就是c[i+j+1]=b[j](因为我这里是考虑j=0开始的,然后自加差就是在交上改动一下就可以了,只要是a[0]!=b[j],就把它放到c[]这个数组里面去~!!!!

1:并集的程序。

求集合LA和集合LB的并集

#define NULL 0

struct JD
{ int data;
struct JD *next;
};

int find(int number,struct JD *h)
{ while(h->data)
{ if(h->data!=number)
{ h=h->next;
continue;
}
else
return 0;
}
return 1;
}

struct JD * make()
{ struct JD *h=NULL,*p=NULL;
int number,tf;
h=(struct JD *)malloc(sizeof(struct JD));
scanf("%d",&h->data);
p=h;
while(p->data)
{ p->next=(struct JD *)malloc(sizeof(struct JD));
p=p->next;
p->data=0;
scanf("%d",&number);
tf=find(number,h);
if(tf)
p->data=number;
else
continue;
}
return h;
}

void print(struct JD *h)
{ while(h->data)
{ printf("%d ",h->data);
h=h->next;
}
}

struct JD * change(struct JD *la,struct JD *lb)
{ struct JD *h,*p,*s,*q;
int number,tf;
p=lb;
while(p->data)
{ number=p->data;
tf=find(number,la);
p=p->next;
if(tf)
{ s=(struct JD *)malloc(sizeof(struct JD));
s->data=number;
s->next=la;
la=s;
}
else
continue;
}
return la;
}

void del(struct JD *h)
{ struct JD *p=h->next;
while(h->data)
{ free(h);
h=p;
p=p->next;
}
free(h);
}

main()
{ struct JD *la,*lb;
printf("\n\nGive the number to LA :\n\n");
la=make();
printf("\nLA is: ");
print(la);
printf("\n\nGive the number to LB :\n\n");
lb=make();
printf("\nLB is: ");
print(lb);
la=change(la,lb);
printf("\n\n\nThe new LA=LA||LB is: ");
print(la);
del(la);
del(lb);
printf("\n\n\nPass any key to exit...!\n");
getch();
}

********** 程序运行结果 **********
Give the number to LA :
1↓
2↓
3↓
5↓
0↓

LA is: 1 2 3 5

Give the number to LB :

6↓
7↓
3↓
2↓
9↓
0↓

LB is: 6 7 3 2 9

The new LA=LA||LB is: 9 7 6 1 2 3 5

--------------------------------------------------
Pass any key to exit...!

㈥ c语言求交集

到底是交集还是并集啊?
求a,b的交集c
调用bing 函数求数组s1,s2的并集s3

㈦ C语言交流

/*
请输入三个整数(逗号隔开): 25,14,36
36 25 14
Press any key to continue

*/
#include <stdio.h>
int main() {
int a,b,c;
printf("请输入三个整数(逗号隔开): ");
scanf("%d,%d,%d",&a,&b,&c);
if(a > b) {
if(b > c) printf("%d %d %d\n\n",a,b,c);
else if(a > c) printf("%d %d %d\n\n",a,c,b);
else printf("%d %d %d\n\n",c,a,b);
}
else if(c > b) printf("%d %d %d\n\n",c,b,a);
else if(a > c) printf("%d %d %d\n\n",b,a,c);
else printf("%d %d %d\n\n",b,c,a);
return 0;
}

㈧ c语言求交

我真不知道你怎么连乘号都没有!!
5x+1,这个电脑可不认识;要用乘除号!(5*x+1)
还有,参数不是用引号括起来的,用括号()
scanf("%f,&x);你的x是int型!这里你的意思是输入浮点型!
pow()返回值是double型,你的y确是整型!
按照下面的程序,就好了。

#include<stdio.h>
#include<math.h>
main()
{

float x,y;
printf("输入x的值\n");
scanf("%f",&x);
y=(pow((5*x+1),3));
printf("y=%f",y);
}

这个我已经,编译过了,没问题

㈨ c语言,为何这不是自然连接而是交

交是R、S中都存在的元组。结果T的属性列应和R、S相同(3),元组个数不大于R、S个数的最小值(3)。
自然连接是由R、S的笛卡尔积去掉重复元组构成的。结果T的属性列应是R、S属性列的和(6),元组个数不大于R、S的元组数之积(3×4)

所以只能是交。

㈩ 怎样用C语言实现集合的并交呢

#include<stdio.h>
#include<stdlib.h>

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<'a')||(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;
}
}

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);
getchar();
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);
}

热点内容
python基础教程源码 发布:2025-07-15 05:56:18 浏览:247
php接受xml 发布:2025-07-15 05:51:04 浏览:927
机顶盒怎么看密码 发布:2025-07-15 05:46:48 浏览:921
电脑配置低怎么变得不卡 发布:2025-07-15 05:34:08 浏览:844
ios火影忍者手游脚本 发布:2025-07-15 05:31:34 浏览:82
iphone支付密码忘了怎么办 发布:2025-07-15 05:30:55 浏览:775
c语言打开网页 发布:2025-07-15 05:21:33 浏览:640
如何制作我的世界模组服务器 发布:2025-07-15 05:21:33 浏览:903
phparray加 发布:2025-07-15 05:20:41 浏览:782
4000以内二手安卓机怎么选 发布:2025-07-15 05:11:25 浏览:644