M4ritimeSeeker

PASS Week 6: Loops, Loops, Loops, Loops...

Oct 5th, 2021 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. Take the SI and PASS Mid-semester Survey!
  2. Take this survey at your leisure, but not during the session.
  3. This will help us leaders by providing anonymous feedback on the program!
  4.  
  5. http://unf.co1.qualtrics.com/jfe/form/SV_8kREAxCL5NjPp66
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. PROBLEM #1: Incrementing and Decrementing
  19.  
  20. Compose a program using a WHILE loop that prints a countdown from 10 to 0.
  21. First, create an increment variable.
  22. Next, create a second decrement variable.
  23. Then, create the loop and print the proper number to the user inside the loop so it behaves as a countdown.
  24.  
  25.  
  26. SAMPLE OUTPUT:
  27.  
  28. 10 9 8 7 6 5 4 3 2 1
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. PROBLEM #2: Looping based on User Input
  48.  
  49. Write a program using a WHILE loop that will prompt the user for a number value of
  50. how many loops the user wants.
  51.  
  52. Starting at 0, print each number counting up until reaching the user's inputted number.
  53. After every 10 iterations of the loop, print a newline character (Use an if statement to accomplish this).
  54. How might you use modulo to control the newline being printed?
  55.  
  56. SAMPLE OUTPUT (User enters 10):
  57.  
  58. Enter in the number of loops: 10
  59. 0 1 2 3 4 5 6 7 8 9
  60.  
  61. MORE SAMPLE OUTPUT (User enters 100):
  62.  
  63. Enter in the number of loops: 100
  64. 0 1 2 3 4 5 6 7 8 9
  65. 10 11 12 13 14 15 16 17 18 19
  66. 20 21 22 23 24 25 26 27 28 29
  67. 30 31 32 33 34 35 36 37 38 39
  68. 40 41 42 43 44 45 46 47 48 49
  69. 50 51 52 53 54 55 56 57 58 59
  70. 60 61 62 63 64 65 66 67 68 69
  71. 70 71 72 73 74 75 76 77 78 79
  72. 80 81 82 83 84 85 86 87 88 89
  73. 90 91 92 93 94 95 96 97 98 99
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. PROBLEM #3: Looping Based on User Input 2
  88.  
  89. Take your solution from problem #2, and edit it to print in descending order instead.
  90. Continue to use a WHILE loop.
  91. As well, limit the input the user can enter to be between 1 and 100 (You may need to use break for this).
  92.  
  93. SAMPLE OUTPUT:
  94.  
  95. Enter an integer between 1 and 100: 80
  96. 80 79 78 77 76 75 74 73 72 71
  97. 70 69 68 67 66 65 64 63 62 61
  98. 60 59 58 57 56 55 54 53 52 51
  99. 50 49 48 47 46 45 44 43 42 41
  100. 40 39 38 37 36 35 34 33 32 31
  101. 30 29 28 27 26 25 24 23 22 21
  102. 20 19 18 17 16 15 14 13 12 11
  103. 10 9 8 7 6 5 4 3 2 1
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. PROBLEM #4: Looping using FOR
  120.  
  121. Write a program using a FOR loop that will print out 100 numbers to screen (similar to
  122. the above program) with 10 numbers per line. DO NOT PROMPT THE USER FOR INPUT.
  123. Does your program print a 0 or a 1 first? If so, how can you adjust that?
  124.  
  125. SAMPLE OUTPUT:
  126.  
  127. 0 1 2 3 4 5 6 7 8 9
  128. 10 11 12 13 14 15 16 17 18 19
  129. 20 21 22 23 24 25 26 27 28 29
  130. 30 31 32 33 34 35 36 37 38 39
  131. 40 41 42 43 44 45 46 47 48 49
  132. 50 51 52 53 54 55 56 57 58 59
  133. 60 61 62 63 64 65 66 67 68 69
  134. 70 71 72 73 74 75 76 77 78 79
  135. 80 81 82 83 84 85 86 87 88 89
  136. 90 91 92 93 94 95 96 97 98 99
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. PROBLEM #5: Factorial
  152.  
  153. https://www.mathsisfun.com/numbers/factorial.html
  154. Write a program that will determine the factorial of a user supplied number using a
  155. for loop.
  156.  
  157.  
  158. SAMPLE OUTPUT:
  159.  
  160. Enter in a number for factorial: 5
  161. Factorial of 5! = 120
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. PROBLEM #6: Do-While Loops
  177.  
  178. Write a program using a DO-WHILE loop that takes integer input from the user.
  179. The user should be prompted to enter positive integer values. If the user enters 0, it will quit.
  180. Data is entered one integer at a time. Zero is used to signify the end of a user’s input.
  181. After the user enters 0, the program will print the minimum, maximum and average integer of ALL the user’s input.
  182. Also, the zero is not a member of the list, don’t use it to determine the average.
  183.  
  184. Test your program with the following data:
  185. 24, 7, 31, 64, 57, 7, 63, 31, 15, 7, 2, 4, and 6.
  186.  
  187. Your min should be 2, max should be 64 and average should be 24.46 with this test
  188. data.
  189.  
  190.  
  191. SAMPLE OUTPUT:
  192.  
  193. Enter a positive integer or 0 to stop and provide statistics: 6
  194. Enter a positive integer or 0 to stop and provide statistics: 7
  195. Enter a positive integer or 0 to stop and provide statistics: 8
  196. Enter a positive integer or 0 to stop and provide statistics: 9
  197. Enter a positive integer or 0 to stop and provide statistics: 10
  198. Enter a positive integer or 0 to stop and provide statistics: 0
  199. Min: 6 Max: 10 Avg: 8.00
Add Comment
Please, Sign In to add comment