I was writing a program for finding out Intersection of two sorted arrays in C language. The code works fine when I compile it with GCC on my machine and run it, but gives a runtime error on ideone.com.
Here is the Live link to the below code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int arr1[] = {1,3,4,5,7,11,123};
int arr2[] = {2,3,5,6,7,8,9,11,23,123};
int i, j=0, k=0, l1, l2;
l1 = sizeof(arr1)/ sizeof(arr1[0]);
l2 = sizeof(arr2)/ sizeof(arr2[0]);
while(j<l1 && k<l2){
if(arr1[j]<arr2[k]){
j++;
}
else if(arr1[j]>arr2[k]){
k++;
}
else{
printf("%d\t", arr1[j]);
j++; k++;
}
}
}
I am not very sure, as your code looks good.
However, adding a
return 0;
at the end ofmain()
gives a success. Maybe, a constrain with the on-line compiler itself.Also, changed
int main()
toint main(void)
, but that is of no importance here.see LIVE CODE