You are on page 1of 1

LINEAR SEARCH PROGRAM

#include<stdio.h>
#include<conio.h> #include<stdlib.h> void main(){ int arr[100],i,element,no; clrscr(); printf("\nEnter the no of Elements: "); scanf("%d", &no); for(i=0;i<no;i++){ printf("\n Enter Element %d: ", i+1); scanf("%d",&arr[i]); } printf("\nEnter the element to be searched: "); scanf("%d", &element); for(i=0;i<no;i++){ if(arr[i] == element){ printf("\nElement found at position %d",i+1); getch(); exit(1); } } printf("\nElement not found"); getch(); } Output: Enter the no of Elements: 5 Enter Element 1: 12 Enter Element 2: 23 Enter Element 3: 52 Enter Element 4: 23 Enter Element 5: 10 Enter the element to be searched: 23 Element found at position 2

You might also like