/*Program to search an element in an array using linear search method */
main()
{
int a[50],i,n,searching_element, flag=0;
printf("\n Enter the number of elements : ");
scanf("%d",&n);
printf("\nEnter the elements of array a - ");
for(i=0; i < n; i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the element to be searched ");
scanf("%d",&searching_element);
/*Searching Process */
for(i=0; i < n; i++)
{
if(searching_element==a[i])
{
flag=1;
break;
}
}
if(flag==0)
printf("\nSearching Element %d not found in the array ",searching_element);
else
printf("\nSearching Element %d found in the array ",searching_element);
}
main()
{
int a[50],i,n,searching_element, flag=0;
printf("\n Enter the number of elements : ");
scanf("%d",&n);
printf("\nEnter the elements of array a - ");
for(i=0; i < n; i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the element to be searched ");
scanf("%d",&searching_element);
/*Searching Process */
for(i=0;
if(searching_element==a[i])
printf("\nSearching Element %d not found in the array ",searching_element);
else
printf("\nSearching Element %d found in the array ",searching_element);
}
Comments
Post a Comment