Advertisement
Guest User

Untitled

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