Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. int main()
  5. {
  6. int i,key,a[7],choice;
  7. do{
  8. menu:
  9. system("cls");
  10. printf("\n Linear Search Demo: \n----------\n");
  11. printf("\n \n Exit: \t 0\n");
  12. printf("\n\n Search: \t 1 \n ");
  13.  
  14. printf("\n Which operation do you want to perform?");
  15. scanf("%d", &choice);
  16.  
  17. switch(choice)
  18. {
  19. case 1:
  20. printf("\n Enter the list: \n");
  21. for(i=0;i<7;i++)
  22. {
  23. scanf("%d",&a[i]);
  24. }
  25.  
  26. printf("\n Enter a search key:\n");
  27. scanf("%d",&key);
  28. for(i=0;i<7;i++)
  29. {
  30. if(key==a[i]){
  31. printf("\n Key Founf!\n");
  32. getch();
  33. goto menu;
  34.  
  35. }
  36. }
  37. printf("key not found!\n"); getch(); break;
  38.  
  39. case 0: printf("\n Sayonara !") ; getch(); return 0;
  40. default: printf ("\n Invalid input! Type [0-1]!\n");
  41. getch();
  42. }
  43. }while (1);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement