/*write a c program for implementing linear search method using function*/
#include<stdio.h>
#include<conio.h>
void search();
void main()
{
clrscr();
search();
getch();
}
void search()
{
int a[20],n,num,i,flag=0;
printf("\nenter how many number you want:-");
scanf("%d",&n);
printf("\nenter the element:-");
for(i=0;i<n;i++)
scanf("\n%d",&a[i]);
printf("\nenter the which number you want to search:-");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
flag=1;
break;
}
}
if(flag==1)
printf("\nthe number %d is found at %d location",num,i+1);
else
printf("\nnumber not found");
}
/*
enter how many number you want:-4
enter the element:-6
3
1
4
enter the which number you want to search:-3
the number 3 is found at 2 location
enter how many number you want:-4
enter the element:-7
8
9
4
enter the which number you want to search:-3
number not found */
No comments:
Post a Comment