Linear Search In C Programming

Introduction
  • In this blog, I am going to explain how to find the linear search in C programming.
  • It is used to find whether the given number is present in an array or not. If it has means then it can find the location of an array. 
Software Requirements
  • Turbo C++ or C. 
Programming
  1. #include < stdio.h >   
  2. int main()   
  3. {  
  4.     int array[100], search, c, n;  
  5.     printf("Enter the number of elements in array\n");  
  6.     scanf("%d", & n);  
  7.     printf("Enter %d integer(s)\n", n);  
  8.     for (c = 0; c < n; c++) scanf("%d", & array[c]);  
  9.     printf("Enter the number to search\n");  
  10.     scanf("%d", & search);  
  11.     for (c = 0; c < n; c++) {  
  12.         if (array[c] == search) {  
  13.             printf("%d is present at location %d.\n", search, c + 1);  
  14.             break;  
  15.         }  
  16.     }  
  17.     if (c == n) printf("%d is not present in array.\n", search);  
  18.     return 0;  
  19. }  
Explanation
  • It is very simple programming and the linear search is always known as Sequential search. With the help of programming, the linear search of an array can be found.

    programming

    programming
Output

Output
Ebook Download
View all
Learn
View all