# Using C language to find the intersection and of lines in two-dimensional array

CSDN Q & A 2021-12-30 05:30:17 阅读数:915

using language intersection lines two-dimensional

Each row of a two-dimensional array holds a set of integers , share 5 A collection of , Each set contains 5 Elements . Write a program to find the intersection of these five sets , And the number of elements in the intersection . The so-called intersection means that all appear here at the same time 5 A collection of elements in a collection . The five sets are ： {12,35,3,9,0},{2,35,9,12,1},{35,12,0,1,9},{4,90,35,9,12},{11,9,0,12,35}

Define a function to find the intersection of two arrays , A two-dimensional array is nothing more than recycling the intersection of two arrays and finding the intersection of the next array

``````#include <stdio.h>void jj(int *a,int *b,int *c,int *n){ int i,j,k=0; for(i=0;i<*n;i++) for(j=0;j<5;j++) { if(a[i] == b[j]) { c[k++] = b[j]; break; } } *n = k;}int main(){ int a = {
{
12,35,3,9,0},{
2,35,9,12,1},{
35,12,0,1,9},{
4,90,35,9,12},{
11,9,0,12,35}}; int b,i; int n = 5; for(i=0;i<4;i++) { if(i==0) jj(a[i],a[i+1],b,&n); else jj(b,a[i+1],b,&n); } printf("%d\n",n); for(i=0;i<n;i++) printf("%d ",b[i]); return 0;}``````