Google Search

Saturday, October 24, 2015

Linear Searching using C Programming

‪#‎include‬<stdio.h>
#include<conio.h>
void main()
{
int a[15],i,n;
int ele,temp=0,pos=0;
clrscr();
printf("\nEnter the term: ");
scanf("%d",&n);
printf("\nEnter the array elements: ");
for (i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the element to be search: ");
scanf("%d",&ele);
// searching for the element
for (i=0; i<n; i++)
{
if (a[i]==ele)
{
temp=1;
pos=i;
}
}
if (temp==1)
{
printf("Element found %d , position==%d",ele,pos);
}
else
{
printf("Element not found\n");
}
getch();
}

No comments:

Post a Comment