Signup/Sign In

Linear Search Program In C Language

Learn C language tutorial

Linear Search:

  • Linear Search will search the given element from the leftmost node,
  • If the element is found it will return the index of the given element,
  • You can learn more about Linear Search Algorithm from here

Program For Liner Search Using C Program:

/* Linear Search Using C */

#include <stdio.h>
int search(int arr[], int i, int val) {
  for (int y = 0; y < i; y++)
    if (arr[y] == val)
      return y;
  return -1;
int main() {
  int arr[] = {32, 54, 71, 89, 44};
  int val = 89;
  int i = sizeof(arr) / sizeof(arr[0]);

  int linear = search(arr, i, val);

  (linear == -1) ? printf("The Given Element Is Not Found At Any Index") : printf("The Given Element 89 Found At Index Of: %d", linear);



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight