Professional Documents
Culture Documents
DS Ex3
DS Ex3
03
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
void linear()
{int a[]={1,3,5,7,9};
int item;
int n=5;
int i=0;
int flag=0;
}
void main()
{
int ch;
int element;
while(1)
{printf("\n MENU\n Select your operation:\n1.Linear Search\n2.Binary
Search\n3.Exit");
printf("\n Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter element to be searched");
scanf("%d",&element);
linear(element);
break;
case 2:
binary(element);
break;
case 3:
exit(0);
default:
printf("INVALD INPUT");
}
}
}
Output:
MENU
Select your operation:
1.Linear Search
2.Binary Search
3.Exit
Enter your choice:1
Enter element to be searched7
The original array element are:
a[0]=1
a[1]=3
a[2]=5
a[3]=7
a[4]=9
enter key to be searched7
Found element 7 at position 3
MENU
Select your operation:
1.Linear Search
2.Binary Search
3.Exit
Enter your choice:1
Enter element to be searched10
The original array element are:
a[0]=1
a[1]=3
a[2]=5
a[3]=7
a[4]=9
enter key to be searched10
Element not found
MENU
Select your operation:
1.Linear Search
2.Binary Search
3.Exit
Enter your choice:2
Enter the number of element:3
Enter the element into array:7
10
11
Enter the key to be searched:11
Element found
MENU
Select your operation:
1.Linear Search
2.Binary Search
3.Exit
Enter your choice:2
Enter the number of element:3
Enter the element into array:7
10
11
Enter the key to be searched:3
Element not found
MENU
Select your operation:
1.Linear Search
2.Binary Search
3.Exit
Enter your choice:3