M4ritimeSeeker

PASS Week 7: Next iteration, Nested Loops

Oct 12th, 2021 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 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. PROBLEM #1
  17.  
  18. Construct a program that uses two nested for loops to print 10 lines of 10
  19. integers that shows the row and column position.
  20.  
  21. The first loop represents the ROWS.
  22. The nested loop (second loop) represents each COLUMN in a row.
  23.  
  24. The first number in the brackets is the row and the second is the column.
  25. Your output should look something like this:
  26.  
  27. [0,0] [0,1] [0,2] [0,3] [0,4] [0,5] [0,6] [0,7] [0,8] [0,9]
  28. [1,0] [1,1] [1,2] [1,3] [1,4] [1,5] [1,6] [1,7] [1,8] [1,9]
  29. [2,0] [2,1] [2,2] [2,3] [2,4] [2,5] [2,6] [2,7] [2,8] [2,9]
  30. [3,0] [3,1] [3,2] [3,3] [3,4] [3,5] [3,6] [3,7] [3,8] [3,9]
  31. [4,0] [4,1] [4,2] [4,3] [4,4] [4,5] [4,6] [4,7] [4,8] [4,9]
  32. [5,0] [5,1] [5,2] [5,3] [5,4] [5,5] [5,6] [5,7] [5,8] [5,9]
  33. [6,0] [6,1] [6,2] [6,3] [6,4] [6,5] [6,6] [6,7] [6,8] [6,9]
  34. [7,0] [7,1] [7,2] [7,3] [7,4] [7,5] [7,6] [7,7] [7,8] [7,9]
  35. [8,0] [8,1] [8,2] [8,3] [8,4] [8,5] [8,6] [8,7] [8,8] [8,9]
  36. [9,0] [9,1] [9,2] [9,3] [9,4] [9,5] [9,6] [9,7] [9,8] [9,9]
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /*** SKELETON CODE ***/
  43.  
  44. #include <stdio.h>
  45.  
  46. #define ROWS 10
  47. #define COLS 10
  48.  
  49. int main(void)
  50. {
  51.  
  52. return 0;
  53. }//end main
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. PROBLEM #2
  69.  
  70. Analyze the program below. How might you use a break and continue statement to stop
  71. and prompt the user for a new input after 4 loops, and then skip the second else if?
  72.  
  73. #include <stdio.h>
  74.  
  75. int main(void)
  76. {
  77. int input = 5;
  78. int counter = 0;
  79.  
  80. while(counter++ < 100) {
  81. printf("I am in loop #: %2d\n",counter);
  82. if(counter == 4){
  83. printf("Enter in a new input: ");
  84. scanf(" %d", &input);
  85. //I want to enter the next iteration of the loop here
  86. }
  87. else if(counter >= 10) {
  88. printf("I am breaking out of this.\n");
  89. //I want to exit the loop here
  90. }
  91. }
  92. return 0;
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. PROBLEM #3
  112.  
  113. Write a program that will calculate the area of a square using
  114. a length input from the user.
  115.  
  116. Compute the area using the pow() function in the <math.h> library.
  117.  
  118. Print out the area of the square 2 decimal places to the right.
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. PROBLEM #4
  134.  
  135. Write a program that generates a random number using the rand() function.
  136.  
  137. Run the program 2-3 times and observe the results.
  138.  
  139. Afterwards, add the srand() call with the time() argument to add randomness to the numbers.
  140. You only need to call srand() once in the program before the rand() calls.
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. PROBLEM #5
  159.  
  160. Create a program that will generate a random set of numbers between 10 and 20, inclusively.
  161.  
  162. Print the number to the screen a couple of times.
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. PROBLEM #6
  179.  
  180. Write a program that simulates flipping a coin for 1000 times
  181. and report the number of heads and tails you get.
  182.  
  183. Use a for loop to control the amount of coin flips.
  184. Your heads and tails variables are used to KEEP TRACK of how many times heads or tails occurs.
  185.  
  186. NOTE: use the random number generator.
  187.  
  188.  
  189.  
Add Comment
Please, Sign In to add comment