I think my solution is not optimal. Although it worked fine and within time limit on Ideone. If someone could check where I fell short would be a great help. Here's my code:
include
void prime(int a,int b){
int i,j,flag;
for(i=a;i<=b;i++){
flag=0;
for(j=2;j<=i/2;j++){
if(i%j==0){
flag=1;
break;
}
}
if(flag==0 && i!=1)
printf("%d\n",i);
}
printf("\n");
}
main(){
int n,arr[20],i,x,y;
scanf("%d",&n);
for(i=0;i<2*n;i++){
scanf("%d",&arr[i]);
}
for(i=0;i<2*n;i++){
if((arr[i]<1000000000)&&(arr[i+1]<1000000000)&&(arr[i+1]-arr[i]<100000)){
x=arr[i];
y=arr[i+1];
}
else
continue;
prime(x,y);
i++;
}
return 0;
}