C Program for Sequential Search of a given number

Description:
It is a simplest form of searching in which the target item is searched by examining the records in the list one by one. If the target item is found then search is stopped, else proceeds to the next record until all records in the list are examined.

Source Code:
/* 
    Program to implement sequential search 
    Author: sourcecodesonline.blogspot.com
*/  
#include<stdio.h>  
#include<stdlib.h>  
#define MAX 10 //Limit for Search list  
int main(void)  
{    int array[MAX],index=0,search_element;  
  printf("\nEnter the search list(10 elements):");  
  for(index=0;index<10;index++)  
   {  
     scanf("%d",&array[index]);  
   }  
   printf("\nEnter the element to be searched:");  
   scanf("%d",&search_element);  
   for(index=0;index<10;index++)  
    {  
      if(array[index]==search_element)  
       {  
            printf("\nElement %d  found at position %d",array[index],index+1);  
            exit(0);  
      }  
    }  
    printf("\nElement %d is not present",search_element);  
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: