Sequential Search C Program

Friday, 6 September 2013

#include<stdio.h>
#include<conio.h>
void main()
{
int f=0,a[10],d=0,c[10],v=0,i,key,n;
clrscr();
printf("Enter the no. of element in the array \n");
scanf("%d",&n);
printf("enter the array elements \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the key element to search");
scanf("%d",&key);
for(i=0;i<n;i++)
{d++;
if(a[i]==key)
{c[v]=a[i];
v++;
f++;
break;
}
}
if(f==0)
{printf("\n key not found\n");
}
else
{printf("\n found");
}
printf("\n comp=%d",d);
getch();
}intf("Result");
if(f==0)
{printf("\n key not found\n");
}
else
{printf("\n found");
}
printf("\n comp=%d",d);
getch();
}

OUTPUT:-

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
Related Posts Plugin for WordPress, Blogger...
 

Most Reading

Labels