fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. int number;
  9. scanf("%d", &number);//n
  10. int array[number];
  11. int i;
  12. for (i=0; i<number; i++)
  13. scanf("%d", &array[i]);
  14. int times;
  15. scanf("%d", times);//m
  16. int search[times];
  17. int j;
  18. for (j=0; j<times; j++)
  19. {
  20. scanf("%d", &search[j]);
  21. i=0;
  22. while(array[i]!=search[j])
  23. {
  24. i++;
  25. if(array[i]==search[j])
  26. {
  27. if(i==0)
  28. printf("%d", array[1]);
  29. else if(i==number)
  30. printf("%d", array[number-1]);
  31. else
  32. printf("%d %d", array[i-1], array[i+1]);
  33. }
  34. if(i>number)
  35. printf("NULL");
  36. }
  37. }
  38.  
  39.  
  40.  
  41. return 0;
  42. }
Runtime error #stdin #stdout 0s 4368KB
stdin
5
89 7890 22 56 87
6
89 7890 22 56 87 999
stdout
Standard output is empty