#include<stdio.h> int sentilinearsearch(int arr[], int size, int target) { int last = arr[size-1]; arr[size - 1] = target; int i=0; while(arr[i] !=target){ i++; } arr[size-1] = last; if(i < size-1 || arr[size - 1]== target){ return i; } else{ return -1; } } int main() { int arr[] = {3,5,1,8,2}; int size = sizeof(arr)/sizeof(arr[0]); int target = 8; int result = sentilinearsearch(arr , size, target); if (result != -1){ printf("element %d is found at index%d\n", target,result); } else{ printf("element %d is not fopund", target); } 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