Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int *common(int a[], int b[], int size, int *plen)
- {
- int i=0,j=0,count=0;
- int *arr;
- int k=0;
- *plen=0;
- for (i=0;i<size;i++)
- {
- for (j=0;j<size;j++)
- {
- if (a[i]==b[j]){
- (*plen)++;
- }
- }
- }
- if (*plen==0)
- return NULL;
- arr=(int*)malloc((*plen)*sizeof(int));
- if (arr==NULL)
- {
- printf("error arr\n");
- return 0;
- }
- for (i=0;i<size;i++){
- for (j=0;j<size;j++){
- if (a[i]==b[j]){
- arr[k]=a[i];
- k++;
- }
- }
- }
- return arr;
- }
- int main()
- {
- int a[5]={1,2,3,4,5};
- int b[5]={1,4,6,8,7};
- int p=0;
- int *i;
- int j=0;
- i=common(a,b,5,&p);
- for (j=0;j<p;j++)
- printf("%d,",i[j]);
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement