fork download
  1. #include <stdio.h>
  2. int search(int arr[], int N, int x)
  3. {
  4. for (int i = 0; i < N; i++)
  5. if (arr[i] == x)
  6. return i;
  7. return -1;
  8. }
  9. int main(void)
  10. {
  11. int arr[] = {3, 6, 1, 4, 7, 5, 2};
  12. int x = 10;
  13. int N = sizeof(arr) / sizeof(arr[0]);
  14.  
  15. // Function call
  16. int result = search(arr, N, x);
  17. (result == -1)
  18. ? printf("Element is not present in array")
  19. : printf("Element is present at index %d", result);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Element is not present in array