Professional Documents
Culture Documents
Code 1
Code 1
ID: 210310571886
Page No:
Aim:
Aim: Write a program to implement Linear Search
Theory: In computer science, a linear search or sequential search is a method for finding an element within a
list. It sequentially checks each element of the list until a match is found or the whole list has been searched.
Algorithm:
else
if the first item of the list has the desired value, return its location ;
else
linearSearch.c
#include<stdio.h>
int main()
int arr[6];
scanf("%d",&arr[i]);
int key;
scanf("%d",&key);
int loc;
if(loc!=-1)
else
printf("Search is unsuccessful\n");
return 0;
if(arr[0] == '/0')
return -1;
else
if(arr[i]==data)
return i+1;
ID: 210310571886
Page No:
}
return -1;
Test Case - 1
User Output
Enter the elements for array: 8 5 4 1 3
Enter the key: 5
Search is successful
loc = 2
Test Case - 2
User Output
Enter the elements for array: 16 25 36 78 54
Enter the key: 26
Search is unsuccessful