You have a major flaw in your main function, try the following code instead.
int main()
{
int ch;
printf("Enter the number of element:");
scanf("%d",&n);
printf("Enter %d elements:\t",n);
for(c=0;c<n;c++)
{
scanf("%d",&a[c]);
}
do
{
printf("Enter that element to search>>");
scanf("%d",&search);
printf("way to search an element...");
printf("\n1.Linear search\n2.Binary search\n");
printf("choose any...>>");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Searching in Linear way...\n");
L_search(search);
break;
case 2:
printf("Searching in binary way...\n");
B_search(search);
break;
case -1:
printf("goodbye.\n");
break;
default :
printf("Invalid option.\nPlease try again\n");
break;
}
} while ( ch != -1);
return 0;
}
Also you have a minor flaw in your
L_search
function, change to (you have to change its prototype as well):
void L_search()
{
for(c=0;c<=n;c++)
{
if (a[c]==search)
{
printf("%d is present at location %d.\n", search, c+1);
return;
}
}
printf("Number Not Found\n");
}
I didn't analyze the
B_search
function, that's left to you as an exercise.
Please note: using global variables is a bad practice, I strongly encourage you to use local variables and pass them as function parameters.