LINEAR
SEARCH
#include<conio.h>
#include<stdio.h>
void main()
{int l,a[10],I,s,f=0,m[9],n=0;
clrscr();
printf(“enter the limit”);
scanf(“%d”,&l);
printf(“enter the numbers”);
for(i=1;i<=l;i++)
scanf(“%d”&a[i]);
printf(“\nenter the number to be
searched”);
scanf(“%d”,&s);
for(i=l;i<=l;i++)
{if(a[i]==s)
{f=1;
m[n]=i;
n++;
}
}
if(f==0)
printf(“\n\nthe number %dis not
present,s”);
else
printf(“\n\n\nthe number is found in
positions”);
for(i=0;i<n;i++)
printf(“%d”,m[i]);
getch();
}
0UTPUT:
Enter the limit:6
Enter the numbers:1 2 20 41 10 20
Enter the number to search 20
The number is found in positions 3 6






0 comments:
Post a Comment