Linear Search in C Program & Flowchart - Sequential Search

In this tutorial, we will learn briefly about linear search then understand flow chart, Program for linear search in C.

It is a basic search technique to find an element from the collection of elements(in sequence) or from an array that why it is also known as Sequential Search. Now I think you have a doubt "Why Linear search basic?" because it is not fast or quick to find the element like other techniques or we can say it is the first searching algorithm touch by anyone who wants to learn searching techniques. 

In this technique, we take one element from the user which we have to find from the sequence of elements and if our program finds then message come out element found at this place else element not found. 

Below I shared Linear Search, Flow Chart and also Source code in C with output. So, All understand it quickly and with the whole knowledge.

linear search flowchart example

Here we discuss the linear search flowchart in which we start from the starting point check elements are present or it has zero element if it contains zero element then direct we can say that element not found else search element if found then print Element found at this position else increase the position by one and if all location have different then from the last position we can say element is not found. Below flowchart explain it in a clear way because vision clear all doubt easily.


linear search flowchart example
Linear Search Flow Chart

Linear Search in C


#include<stdio.h>

int main()
{
int i,flag=0,pos,n,a[5];
printf("Enter elements in array \t");
for(i=0;i<=4;i++)
{
printf("\nEnter element number \t",i+1);
scanf("%d",&a[i]);
}
printf("\nEntered 5 arrray elements are:-");
for(i=0;i<=4;i++)
{
printf("\n\ta[%d]=%d\n",i,a[i]);
}
printf("\nEnter the element to be searched in array");
scanf("%d",&n);
for(i=0;i<=4;i++)
{
if(a[i]==n)
{
printf("\nSearch Successful");
printf("\nElement %d is found at %d position",n,i+1);
flag=1;
break;
}
}
if(flag==0)
{
printf("\nElement does not found");
}
return 0;
}

Output


Enter elements in array
Enter element number    5

Enter element number    4

Enter element number    8

Enter element number    2

Enter element number    0

Entered 5 arrray elements are:-
        a[0]=5

        a[1]=4

        a[2]=8

        a[3]=2

        a[4]=0

Enter the element to be searched in array0

Search Successful
Element 0 is found at 5 position
--------------------------------

In the Above article, We discuss linear search - linear search in c and linear search flowchart and if you have any doubt in the article then comment below.

Happy Coding 😊

2 Comments

If you have any doubts, Please let me know

  1. The number of users accessing websites and web applications on their mobile devices has been increasing steadily. Likewise, popular search engines like Google also use mobile friendliness as a key metric to rank websites. Hence, enterprises nowadays focus on enhancing the mobile user experience of their websites. os path join

    ReplyDelete
Previous Post Next Post

Contact Form