I just tried to this linear search
and it turns out that it displays the else
part. And I don't get what I have done wrong. The logic...
#include<stdio.h>
#include<conio.h>
main()
{
int a[10], i, x, size;
printf("Enter the size of the array: \n");
scanf("%d",&size);
printf("Enter the elements into the array: \n");
for(i=0; i<size; i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element to be searched for: \n");
scanf("%d",&x);
for(i=0; i<size; i++)
{
if(x==a[i])
{
printf("The element is at: %d",i);
break;
}
else
{
printf("The element is not in the array.");
break;
}
}
getch();
}