#include<stdio.h> int search(int arr[],int N,int x) { for(int i=0; i< N; i++) if(arr[i] == x) return i; return -1; } int main(void) { int arr[]={2,3,4,5,10,40}; int x = 10; int N = sizeof(arr) / sizeof(arr[0]); int result = search(arr,N,x); (result == -1) ? printf("element is not present in array") :printf("element is present at index %d",result); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter