#include <stdioh>
main()
{ int a[5]={1,2,3,4,5} , b[5]={3,4,5,6,7};
int inter[5],sum[10],i,j,n=0,m=0,k=5;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
{if(a[i] == b[j]) inter[n++]=a[i];}
printf("交集为:");
for(i=0;i<n;i++)
printf("%d, ",inter[i]);
for(i=0;i<5;i++)
sum[i] = a[i];
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(b[i] != a[j]) {if(j == 4) sum[k++] = b[i];}
else break;
printf("并集为:");
for(i=0;i<k;i++)
printf("%d, ",sum[i]);
}
public class Test {
public static void main(String args[])
{
Set<Integer> a = new HashSet<Integer>(ArraysasList(1, 2, 3, 4, 5));
Set<Integer> b = new HashSet<Integer>(ArraysasList(3, 4, 6, 7, 8));
Set<Integer> c = new HashSet<Integer>(ArraysasList(4, 5, 8, 9, 0));
Set<Integer> aIntersectsB = intersects(a, b);
Set<Integer> aIntersectsC = intersects(a, c);
Set<Integer> bIntersectsC = intersects(b, c);
Set<Integer> abc = intersects(a, bIntersectsC);
Systemoutprintln("a ∩ b: " + aIntersectsB);
Systemoutprintln("a ∩ c: " + aIntersectsC);
Systemoutprintln("b ∩ c: " + bIntersectsC);
Systemoutprintln("a ∩ b ∩ c: " + abc);
}
private static <E> Set<E> intersects(Set<E> set1, Set<E> set2) {
Set<E> intersectSet = new HashSet<E>(set1);
intersectSetretainAll(set2);
return intersectSet;
}
}
以上就是关于根据这已知的数组求交集和并集的C语言程序全部的内容,包括:根据这已知的数组求交集和并集的C语言程序、编写程序求三个集合的交集、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)