Linear search in C source code: This program provides you a simple search experience. This can be a simple code to understand easily. It is a type of search, which is rarely used searching technique. An example program is given at the bottom.
- C program for Factorial, Prime numbers, Armstrong, Strong & Palindrome or not
- Pyramid structure in C program using patterns code
Linear search program in C is also used to find the given input number is present in the array or not by using the searching algorithm. It searches the value in a sequential format and it is a slower than the binary search algorithm. But it processes the multiple functions.
[Read: Software Company List] & [Placement papers download]
Linear search program:
Q: Write a C program for Linear search algorithm.
//Header files
#include<stdio.h>
#include<conio.h>
main()
{
//Program variables
int b[18],ky,j,s=0;
clrscr();//Function to clear previous function
printf("Enter the element to be found");//Display function
scanf("%d",&ky);//Getting input function
for(j=0;j<15;j++)//Looping statement
{
if(j==ky)//Conditional statement
{s=1;break; }
}
// © http://students3k.com
if(s==1)
printf("key number found at %d location");
else
printf(" key number not found");
getch();
}