#include #include // Linear search in an unsorted array. void print_array(int a[], int n) { int i; printf("\nIndex i: "); for(i=0; i< n; i++) printf("%2d, ", i); printf("\nElement a[i]: "); for(i=0; i< n; i++) printf("%2d, ", a[i]); printf("\n\n"); } #define N 12 int main() { int a[N] = { 4, 21, 36, 14, 62, 91, 8, 22, 7, 81, 77, 10}; int i; print_array(a, N); int target = 62; //int target = 72; // Try this target next to see how the search fails int idx=-1; printf("\nSearching for target= %d ...\n", target); for(i=0; i< N; i++) { if(a[i] == target) { idx=i; break; } } if(idx == -1) printf("Target not found.\n\n"); else printf("Target found at index: %d \n\n", idx); system("pause"); }