Data Structures using C Language / Linear Search using C program


1. Write a C program to search an element in the array using Linear Search.

Program
#include 
void main()
{
int a[10],i,se,temp=0; 
//se= search element
printf("Enter Array Elements"); 
for(i=0;i<10;i++)
scanf("%d",&a[i]);

printf("Enter Search Element"); 
scanf("%d",&se);

for(i=0;i<10;i++)
{
if(se==a[i])
{
temp=1; break;
}
}

if(temp==0)
printf("Element Not Found"); 
else
printf("Element Found at Position =%d",i+1); 
}
Output
Enter Array Elements1 9 2 8 3 7 4 5 6 10
Enter Search Element5
Element Found at Position =8



Home     Back