Friday, August 19, 2011

Program to search an element in array using sequential search.

//Program to search an element in array using sequential search.
#include<stdio.h>
#include<conio.h>
void main()
{
 int *a,i,n,loc=-1,num;
 clrscr();
 printf("Enter the number of elements in the array u want:");
 scanf("%d",&n);
 a=(int*) malloc(n*sizeof(int));
 for(i=0;i<n;i++)
 {
   printf(" enter the values of %d elements: ",i);
   scanf("%d",&a[i]);
 }
 printf("\n enter the requried element");
 scanf("%d",&num);
 for(i=0;i<n;i++)
 {
  if(a[i]==num)
  {
   loc=i;
   break;
  }
 }
 if(loc==-1)
 printf("\n element is not found");
 else
 printf("element found at location %d ",loc);
 getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More