Linear Search in Array

Linear Search in Array

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C programming concepts. You can learn C language at your own speed and time. One can learn concepts of C language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Linear Search in Array
Linear Search in Array

Write a C program to Linear Search in Array

PROGRAM: Linear Search in Array

/* Linear Search in Array */
#include<stdio.h>

int main()
{
 int arr[10],i,value,index;
 printf("Please enter 10 values:\n");
 for(i=0;i<10;i++)
  scanf("%d",&arr[i]);
  
 printf("\nEnter a value to be searched: ");
 scanf("%d",&value);
 
 index = -1;
 for(i=0;i<10;i++)
 {
  if(arr[i]==value)
  {
   index=i;
   break;
  }
 }
 
 if(index>=0)
  printf("Value found in Array at %d location",index);
 else
  printf("Value not found in Array");
 return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *