Guest User

Untitled

a guest
Nov 16th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. /*Assignment 4
  2. Sasi Vazik- 203960570
  3. vazik@post.bgu.ac.il*/
  4.  
  5. #include<stdio.h>
  6. #include<string.h>
  7. #include<math.h>
  8.  
  9. //Prototypes:
  10. int Ackerman(int, int);
  11. void Permutations(int);
  12. void Partitions(int);
  13.  
  14. void main(){
  15. int i, choice, ackX, ackY, perm, part;
  16. int numbers[30];
  17. do{
  18. printf("Choose one of the following problems or exit:\n[1] -Run Ackerman function.\n[2] - run Permutations problem.\n[3] - Run Partitions problem.\n[4] - Run Knapsack problem.\n[5] - Exit.\nEnter your choice:\n");
  19. scanf("%d", &choice);
  20. }
  21. while(choice<0 || choice >5);
  22. switch(choice){
  23. case 1:
  24. do{
  25. printf("Enter parameters X and Y for Ackerman function:\n");
  26. scanf("%d", &ackX);
  27. printf("\n");
  28. scanf("%d", &ackY);
  29. if(ackX<0 || ackY<0)
  30. printf("Input Incorrect! X and Y should be more or equal to 0. Please try again.\n");
  31. }
  32. while(ackX<0 || ackY<0);
  33. printf("Ack(%d,%d)=%d", ackX, ackY, Ackerman(ackX, ackY));
  34. break;
  35. case 2:
  36. do{
  37. printf("Enter positive integer greater than 0:\n");
  38. scanf("%d", &perm);
  39. if(perm<=0)
  40. printf("Input Incorrect! Please try again.\n");
  41. }
  42. while(perm<=0);
  43. for(i=0; i<perm; i++)
  44. numbers[i]=i+1;
  45. printf("All permutations of numbers (");
  46. for(i=0; i<perm; i++)
  47. printf("%d ", numbers[i]);
  48. printf("):\n");
  49. Permutations(perm);
  50. break;
  51. case 3:
  52. do{
  53. printf("Enter positive integer greater than 0:\n");
  54. scanf("%d", &part);
  55. if(part<=0)
  56. printf("Input Incorrect! Please try again.\n");
  57. }
  58. while(part<=0);
  59. printf("All partitions of %d", part);
  60. Partitions(part);
  61. break;
  62. case 4:
  63. //sdfjg;lsjd;lf;sjdfgj;sdjfgksdfnmvpnsdnvsoifdnvoisrejgoiesgklhjldsfkg;lshdflkhglkjshfdglkjhsdkjfnviusn
  64. break;
  65. case 5:
  66. break;
  67. }
  68. main();
  69. }
Add Comment
Please, Sign In to add comment