1
0

answer04.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Please fill the functions in this file.
  3. * You can add additional functions.
  4. *
  5. * Hint:
  6. * You can write additonal functions.
  7. * You can test your functions with your own input file.
  8. * See details in README or typing command ./pa04 in terminal after make.
  9. * See output format examples in any of the files in directory expected.
  10. *
  11. * You may create additional arrays if needed. The maximum size
  12. * needed is specified by MAXLENGTH in pa04.h.
  13. */
  14. #include "pa04.h"
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. /*
  18. * =================================================================
  19. * This function prints all partitions of a positive integer value
  20. * For example, if the value is 3:
  21. *
  22. * partitionAll 3
  23. * = 1 + 1 + 1
  24. * = 1 + 2
  25. * = 2 + 1
  26. * = 3
  27. */
  28. void partitionAll(int value)
  29. {
  30. printf("partitionAll %d\n", value);
  31. }
  32. /*
  33. * =================================================================
  34. * This function prints the partitions that use increasing values.
  35. *
  36. * For example, if value is 5
  37. * 2 + 3 and
  38. * 1 + 4 are valid partitions
  39. *
  40. * 5 is a valid partition
  41. *
  42. * 1 + 1 + 3 and
  43. * 2 + 1 + 2 and
  44. * 3 + 2 are invalid partitions.
  45. *
  46. * The program should generate only valid partitions. Do not
  47. * generates invalid partitions and checks validity before printing.
  48. *
  49. */
  50. void partitionIncreasing(int value)
  51. {
  52. printf("partitionIncreasing %d\n", value);
  53. }
  54. /*
  55. * =================================================================
  56. * This function prints the partitions that use Decreasing values.
  57. *
  58. * For example, if value is 5
  59. * 3 + 2 and
  60. * 4 + 1 are valid partitions
  61. *
  62. * 5 is a valid partition
  63. *
  64. * 1 + 1 + 3 and
  65. * 2 + 1 + 2 and
  66. * 2 + 3 are invalid partitions.
  67. *
  68. * The program should generate only valid partitions. Do not
  69. * generates invalid partitions and checks validity before printing.
  70. *
  71. */
  72. void partitionDecreasing(int value)
  73. {
  74. printf("partitionDecreasing %d\n", value);
  75. }
  76. /*
  77. * =================================================================
  78. * This function prints odd number only partitions of a positive integer value
  79. * For example, if value is 5
  80. * 1 + 1 + 1 + 1 + 1 and
  81. * 1 + 3 + 1 are valid partitions
  82. *
  83. * 5 is a valid partition
  84. *
  85. * 1 + 1 + 1 + 2 and
  86. * 2 + 1 + 2 and
  87. * 2 + 3 are invalid partitions.
  88. *
  89. * The program should generate only valid partitions. Do not
  90. * generates invalid partitions and checks validity before printing.
  91. */
  92. void partitionOdd(int value)
  93. {
  94. printf("partitionOdd %d\n", value);
  95. }
  96. /*
  97. * =================================================================
  98. * This function prints even number only partitions of a positive integer value
  99. * For example, if value is 8
  100. * 2 + 2 + 2 + 2and
  101. * 2 + 4 + 2 are valid partitions
  102. *
  103. * 8 is a valid partition
  104. *
  105. * 2 + 1 + 1 + 2 + 2and
  106. * 2 + 1 + 2 + 3and
  107. * 5 + 3 are invalid partitions.
  108. *
  109. * if the value is 5, there will be no result generated
  110. *
  111. * The program should generate only valid partitions. Do not
  112. * generates invalid partitions and checks validity before printing.
  113. */
  114. void partitionEven(int value)
  115. {
  116. printf("partitionEven %d\n", value);
  117. }
  118. /*
  119. * =================================================================
  120. * This function prints alternate ood and even number partitions of a positive integer value. Each partition starts from and odd number, even number, ood number again, even number again...etc.
  121. *
  122. * For example, if value is 6
  123. * 1 + 2 + 1 + 2 and
  124. * 3 + 2 + 1 are valid partitions
  125. *
  126. * 6 is not a valid partition
  127. *
  128. * 2 + 1 + 1 + 2 and
  129. * 2 + 1 + 3and
  130. * 5 + 1 are invalid partitions.
  131. *
  132. * The program should generate only valid partitions. Do not
  133. * generates invalid partitions and checks validity before printing.
  134. */
  135. void partitionOddAndEven(int value)
  136. {
  137. printf("partitionOddAndEven %d\n", value);
  138. }
  139. /*
  140. * =================================================================
  141. * This function prints prime number only partitions of a positive integer value
  142. * For example, if value is 6
  143. * 2 + 2 + 2 and
  144. * 3 + 3 are valid partitions
  145. *
  146. * 6 is not a valid partition
  147. *
  148. * 2 + 4 and
  149. * 1 + 5 are invalid partitions.
  150. *
  151. * The program should generate only valid partitions. Do not
  152. * generates invalid partitions and checks validity before printing.
  153. */
  154. void partitionPrime(int value)
  155. {
  156. printf("partitionPrime %d\n", value);
  157. }