M4ritimeSeeker

PASS Week 9/15

Sep 14th, 2020 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. Problem #1
  2.  
  3. Determine the outcomes of the following expressions in ‘C’. Consider the data types of each operand and each result.
  4. Program these in a code editor to see if your predictions hold true!
  5.  
  6. 1. 10 * 3
  7. 2. True * 4
  8. 3. ‘A’ * 2
  9. 4. 22.3 * 2
  10. 5. 10 / 3
  11. 6. True / 4
  12. 7. 22.3 / 2
  13. 8. 3 / 5
  14. 9. float(3 % 5)
  15. 10. 3 % (double) 7
  16.  
  17.  
  18. Problem #2
  19.  
  20. Given the expressions below, add parentheses to determine the order in which operations will be carried out in the
  21. expressions. Code these in a code editor and see if your predictions hold true!
  22.  
  23. 1. 3 * 8 / 4 % 4 * 5
  24. 2. a += b *= c ‐= 5
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. Problem #3 Get the least significant value of an integer
  34.  
  35. Compose a program using modulo to get the rightmost (least significant digit) of an integral
  36. number. We want to use modulo to filter out all but the ones value place. Hint if we remove the tens place, we also remove anything above it, leaving the ones place value.
  37.  
  38. /** SKELETON CODE **/
  39.  
  40. #include <stdio.h>
  41.  
  42. int main(void)
  43. {
  44. //Local Declarations
  45. int intNum = 0;
  46. int lsDigit = 0;
  47.  
  48.  
  49. //Local Statements
  50.  
  51.  
  52.  
  53. return 0;
  54. }//end main
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. Problem #4 Quotient and Remainder
  69.  
  70. Compose a program that uses both division and modulo to determine and print out the
  71. quotient and remainder of two integer values provided by the user at runtime.
  72.  
  73. /** SKELETON CODE **/
  74.  
  75. #include <stdio.h>
  76.  
  77. int main(void)
  78. {
  79. //Local declarations
  80. int intNum1 = 0;
  81. int intNum2 = 0;
  82. int intCalc = 0;
  83.  
  84. //Local Statements
  85. printf("Supply two integral values: ");
  86.  
  87.  
  88. //Calculate quotient here
  89.  
  90. //Calculate any remainder here
  91.  
  92. return 0;
  93. }//end main
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. Problem #5 (Shifty Business)
  107.  
  108. Compose a program that declares a defined literal value of 9876543201 called ALONGNBR.
  109. Now you will add printf() statements to manipulate the value stored to accomplish shifting
  110. to the right, the left and to return rightmost values, printing them to output. The first
  111. printf() statement will use the division operator to shift the defined number to the right 4
  112. places, effectively truncating the 3201 values. The second printf() statement should use the
  113. modulo operator to return the 2 right most values form the defined number. The last
  114. printf() statement should use the multiplication operator to shift the number two places to
  115. the left. When you print out the last statement your format modifier should use %lld for a
  116. long long integer.
  117.  
  118. (See Picture)
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. Problem #6 A rounding program
  132.  
  133. Compose a program that will take a floating point number as input and will round the
  134. number to the hundredth place of accuracy, rounding up. So if the user enters in the value
  135. 2.345 the program will round the number to 2.35 and output it to the screen. You should
  136. use shifting to accomplish your task. First design the algorithm that your program must
  137. perform to accomplish the task. Now program it, using print statements as needed to verify
  138. your answers if need be for troubleshooting. Hint: My solution involves moving the
  139. values to the left, performing a conversion (cast) to int, then shifting the number
  140. back to the right and converting it back to a floating point data type. NOTE: printing a
  141. value to screen can round the output as its presented, but the actual value in
  142. memory that is being used for math operations is not rounded, which can cause
  143. errors hidden by the rounded output.
Add Comment
Please, Sign In to add comment