M4ritimeSeeker

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

Feb 23rd, 2022 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 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. https://unf.co1.qualtrics.com/jfe/form/SV_3xy2D1S0x8nsR26
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. As well, here are the transcribed questions and answers to today's Kahoot:
  13. https://pastebin.com/F00C8Mf0
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. PROBLEM #1: Simple Countdown
  34.  
  35. Compose a program using a WHILE loop that prints a countdown from 10 to 0.
  36.  
  37. SAMPLE OUTPUT:
  38.  
  39. 10 9 8 7 6 5 4 3 2 1
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. PROBLEM #2: Looping based on User Input
  59.  
  60. Write a program using a WHILE loop that will print a number counting up based
  61. on a user input.
  62.  
  63. Starting at 0, print each number counting up UNTIL IT REACHES the user's inputted number.
  64. After every 10 iterations of the loop, print a newline character (Use an if statement to accomplish this, you may need modulo).
  65.  
  66.  
  67. SAMPLE OUTPUT (User enters 10):
  68.  
  69. Enter in the number of loops: 10
  70. 0 1 2 3 4 5 6 7 8 9
  71.  
  72.  
  73. MORE SAMPLE OUTPUT (User enters 100):
  74.  
  75. Enter in the number of loops: 100
  76. 0 1 2 3 4 5 6 7 8 9
  77. 10 11 12 13 14 15 16 17 18 19
  78. 20 21 22 23 24 25 26 27 28 29
  79. 30 31 32 33 34 35 36 37 38 39
  80. 40 41 42 43 44 45 46 47 48 49
  81. 50 51 52 53 54 55 56 57 58 59
  82. 60 61 62 63 64 65 66 67 68 69
  83. 70 71 72 73 74 75 76 77 78 79
  84. 80 81 82 83 84 85 86 87 88 89
  85. 90 91 92 93 94 95 96 97 98 99
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. PROBLEM #3: Looping Based on User Input 2
  100.  
  101. Take your solution from problem #2, and edit it to print in descending order instead.
  102. USE A FOR LOOP INSTEAD.
  103. As well, limit the input the user can enter to be between 1 and 100 (You may need to use break for this).
  104.  
  105. SAMPLE OUTPUT:
  106.  
  107. Enter an integer between 1 and 100: 80
  108. 80 79 78 77 76 75 74 73 72 71
  109. 70 69 68 67 66 65 64 63 62 61
  110. 60 59 58 57 56 55 54 53 52 51
  111. 50 49 48 47 46 45 44 43 42 41
  112. 40 39 38 37 36 35 34 33 32 31
  113. 30 29 28 27 26 25 24 23 22 21
  114. 20 19 18 17 16 15 14 13 12 11
  115. 10 9 8 7 6 5 4 3 2 1
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. PROBLEM #4: Print a number backwards one digit at a time
  133.  
  134. Write a program that gets an integer from a user and prints out the number backwards.
  135. Using modulo and division, print the RIGHT-MOST DIGIT of that number iteratively using a loop.
  136. You may use a for or while loop.
  137. Recall that using division can reduce a number by a power of 10 (For example, 1234 divided by 10 would give you 123)
  138. and modulo can be used to get the digit in the tens place.
  139.  
  140. SAMPLE OUTPUT
  141.  
  142. Enter a number and I will print it backward: 1234
  143. 4321
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. PROBLEM #5: Factorial
  166.  
  167. https://www.mathsisfun.com/numbers/factorial.html
  168. Write a program that will determine the factorial of a user supplied number using a
  169. for loop.
  170.  
  171.  
  172. SAMPLE OUTPUT:
  173.  
  174. Enter in a number for factorial: 5
  175. Factorial of 5! = 120
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. PROBLEM #6: Do-While Loops
  196.  
  197. Write a program using a DO-WHILE loop that takes integer input from the user.
  198. The user should be prompted to enter positive integer values. If the user enters 0, it will quit.
  199. Data is entered one integer at a time. Zero is used to signify the end of a user’s input.
  200. After the user enters 0, the program will print the minimum, maximum and average integer of ALL the user’s input.
  201. Also, the zero is not a member of the list, don’t use it to determine the average.
  202.  
  203. Test your program with the following data:
  204. 24, 7, 31, 64, 57, 7, 63, 31, 15, 7, 2, 4, and 6.
  205.  
  206. Your min should be 2, max should be 64 and average should be 24.46 with this test
  207. data.
  208.  
  209.  
  210. SAMPLE OUTPUT:
  211.  
  212. Enter a positive integer or 0 to stop and provide statistics: 6
  213. Enter a positive integer or 0 to stop and provide statistics: 7
  214. Enter a positive integer or 0 to stop and provide statistics: 8
  215. Enter a positive integer or 0 to stop and provide statistics: 9
  216. Enter a positive integer or 0 to stop and provide statistics: 10
  217. Enter a positive integer or 0 to stop and provide statistics: 0
  218. Min: 6 Max: 10 Avg: 8.00
Add Comment
Please, Sign In to add comment