Write a C Program for Linear Search



LineAR search, Sumit Kar, Timus Rak


#include<stdio.h>


void main()

{

 int arr[10],i,value,index;

 printf("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, %d index",index+1,index);

 else

  printf("Value not found in Array");








}


Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C