In: Computer Science
Propose an algorithm in C to match numbers / tokens (words) from one array to another array and pull out the matching numbers.
CODE: C Programming Language
#include<stdio.h>
void printMatching(int arr1[],int n1,int arr2[],int n2){
int i,j;
for(i=0;i<n1;i++){
for(j=0;j<n2;j++){
if(arr2[j]==arr1[i]){
printf("%d ",arr1[i]);
break;
}
}
}
}
int main(){
int arr1[]= {10,20,30,40,50};
int arr2[]= {10,30,40,60,70};
int n1 = sizeof(arr1)/sizeof(arr1[0]);
int n2 = sizeof(arr2)/sizeof(arr2[0]);
printMatching(arr1,n1,arr2,n2);
return 0;
}
======================================================================
SCREENSHOT OF THE CODE:
======================================================================
OUTPUT:
Thank you. Please ask me if you have any doubt.