Develop a ‘C’ program to create and implement LINEAR SEARCHING.

 

DATA STRUCTURE & ALGORITHM USING C – LAB (2018407)

UNIT – 14

Develop a ‘C’ program to create and implement LINEAR SEARCHING.

 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100], n, i, item, loc=-1;
clrscr();
printf("\nEnter the number of element :");
scanf("%d", &n);
printf("Enter the numbers : \n");
for(i=0;i<=n-1;i++)
 {
  scanf("%d", &a[i]);
 }
printf("\nEnter the number to be searched :");
scanf("%d", &item);
for(i=0;i<=n-1;i++)
{
  if(item == a[i])
  {
   loc = i;
   break;
  }
}
if(loc>=0)
 {
  printf("\n%d is found in position %d :", item, loc+1);
 }
else
 {
  printf("\n Item does not exist");
 }
getch();
}


Post a Comment

0 Comments