This is the program for Linear Search in a 1-D Array.
#include<stdio.h> int main(){ int k, a[50], n, i; printf("enter the no of elements you want to add : "); scanf("%d",&n); printf("enter the array elements : "); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("enter the element you want to search : "); scanf("%d",&k); for(i=0;i<n;i++){ if(k==a[i]){ printf("element found at %d location.",i+1); break; } if(i==n){ printf("element not found."); }} return 0; }
0 Comments