题目
有两个数组,每个数组的元素都是有序的,现在通过对比查找两个数组中第一个相同的元素,并显示出来。
比如:a[ ]={1,5,9},b[ ]={2,4,5 },那么第一个相同元素是5。
实现代码
/* ============================= Name : 20200621.c Author : 折腾的小大叔 Version : Copyright : Your copyright notice Description : ============================= */#include #include int * FindFirstSameElement(int *pA,int numA,int *pB,int numB){int *ptA,*ptB;ptA=pA;ptB=pB;while((ptA*ptB){ptB++;}else{ptA++;}}}return 0;}int main(void){int a[]={1,2,3,4,5,6,7,8,9};int b[]={5,7,8,9,11,15};int i;int *temp;printf("第一个有序数组是:");for(i=0;i
运行结果
往期推荐
C语言每日一练19——分解质因数
C语言每日一练18——递归方法整数逆序
C语言每日一练17——递归方法求阶乘n