Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int i,key,a[7],choice;
- do{
- menu:
- system("cls");
- printf("\n Linear Search Demo: \n----------\n");
- printf("\n \n Exit: \t 0\n");
- printf("\n\n Search: \t 1 \n ");
- printf("\n Which operation do you want to perform?");
- scanf("%d", &choice);
- switch(choice)
- {
- case 1:
- printf("\n Enter the list: \n");
- for(i=0;i<7;i++)
- {
- scanf("%d"&a[i]);
- }
- printf("\n Enter a search key:\n");
- scanf("%d",&key);
- for(i=0;i<7;i++)
- {
- if(key==a[i]){
- printf("\n Key Founf!\n");
- getch();
- goto menu;
- }
- }
- printf("key not found!\n"); getch(); break;
- case 0: printf("\n Sayonara !") ; getch(); return 0;
- default: printf ("\n Invalid input! Type [0-1]!\n");
- getch();
- }
- }while (1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement