write a program of linear search search.
#include<conio.h>
#include<stdio.h>
void main()
{
int arr[50],v,i,count=0,f;
clrscr();
printf("how many alements you want to enter");
scanf("%d",&v);
printf("\nenter %d integer data elements\n",v);
for(i=0;i<v;i++)
{
scanf("%d",&arr[i]);
}
printf("enter the element you want to search");
scanf("%d",&f);
for(i=0;i<v;i++)
{
count++;
if(arr[i]==f)
{
break;
}
}
if(arr[i]==f)
{
printf("%d is found at location %d",f,count);
}
else
{
printf("%d is not present in the enterd elements",f);
}
getch();
}
#include<conio.h>
#include<stdio.h>
void main()
{
int arr[50],v,i,count=0,f;
clrscr();
printf("how many alements you want to enter");
scanf("%d",&v);
printf("\nenter %d integer data elements\n",v);
for(i=0;i<v;i++)
{
scanf("%d",&arr[i]);
}
printf("enter the element you want to search");
scanf("%d",&f);
for(i=0;i<v;i++)
{
count++;
if(arr[i]==f)
{
break;
}
}
if(arr[i]==f)
{
printf("%d is found at location %d",f,count);
}
else
{
printf("%d is not present in the enterd elements",f);
}
getch();
}
No comments:
Post a Comment