Embed presentation
Downloaded 14 times
![S9-1
Write a program in ‘C’ language to implement linear search using pointers.
# include<stdio.h>
main()
{
int arr[20],*p, n,i,item;
clrscr();
printf("How many elements you want to enter in the array : ");
scanf("%d",&n);
for(i=0; i < n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d", &arr[i]);
}
printf("Enter the element to be searched : ");
scanf("%d",&item);
p=arr;
for(i=0;i < n;i++)
{
if(item == *p)
{
printf("%d found at position %dn",item,i+1);
break;
}
p++;
}/*End of for*/
if(i == n)
printf("Item %d not found in arrayn",item);
getch();
}
Page 1](https://image.slidesharecdn.com/bcsl-033dataandfilestructureslabs9-1-160515012844/85/Program-in-C-language-to-implement-linear-search-using-pointers-1-320.jpg)

The document contains a C program that implements a linear search algorithm using pointers. It prompts the user to input an array of elements and a search item, then searches for that item in the array. If found, it prints the position of the item; otherwise, it indicates that the item is not present.
![S9-1
Write a program in ‘C’ language to implement linear search using pointers.
# include<stdio.h>
main()
{
int arr[20],*p, n,i,item;
clrscr();
printf("How many elements you want to enter in the array : ");
scanf("%d",&n);
for(i=0; i < n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d", &arr[i]);
}
printf("Enter the element to be searched : ");
scanf("%d",&item);
p=arr;
for(i=0;i < n;i++)
{
if(item == *p)
{
printf("%d found at position %dn",item,i+1);
break;
}
p++;
}/*End of for*/
if(i == n)
printf("Item %d not found in arrayn",item);
getch();
}
Page 1](https://image.slidesharecdn.com/bcsl-033dataandfilestructureslabs9-1-160515012844/85/Program-in-C-language-to-implement-linear-search-using-pointers-1-320.jpg)