Write a program for linear search


#include<stdio.h>
main()
{
      int a[100],item,num,i;
      
      printf("\nEnter the number of elements :");
      scanf("%d",&num);
      
      printf("\nEnter the array elements :");
      for(i=0;i<num;i++)
      scanf("%d",&a[i]);
      
      printf("\nEnter the item to search :");
      scanf("%d",&item);
      
      for(i=1;i<num;i++)
      if(item==a[i])
      {
        printf("\nItem %d is found at %d position",item,i+1);
        end();
      }
      printf("\nItem not found.");
      getch();
}

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Migrating database from ASP.NET Identity to ASP.NET Core Identity