Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem #1
- Determine the outcomes of the following expressions in ‘C’. Consider the data types of each operand and each result.
- Program these in a code editor to see if your predictions hold true!
- 1. 10 * 3
- 2. True * 4
- 3. ‘A’ * 2
- 4. 22.3 * 2
- 5. 10 / 3
- 6. True / 4
- 7. 22.3 / 2
- 8. 3 / 5
- 9. float(3 % 5)
- 10. 3 % (double) 7
- Problem #2
- Given the expressions below, add parentheses to determine the order in which operations will be carried out in the
- expressions. Code these in a code editor and see if your predictions hold true!
- 1. 3 * 8 / 4 % 4 * 5
- 2. a += b *= c ‐= 5
- Problem #3 Get the least significant value of an integer
- Compose a program using modulo to get the rightmost (least significant digit) of an integral
- 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.
- /** SKELETON CODE **/
- #include <stdio.h>
- int main(void)
- {
- //Local Declarations
- int intNum = 0;
- int lsDigit = 0;
- //Local Statements
- return 0;
- }//end main
- Problem #4 Quotient and Remainder
- Compose a program that uses both division and modulo to determine and print out the
- quotient and remainder of two integer values provided by the user at runtime.
- /** SKELETON CODE **/
- #include <stdio.h>
- int main(void)
- {
- //Local declarations
- int intNum1 = 0;
- int intNum2 = 0;
- int intCalc = 0;
- //Local Statements
- printf("Supply two integral values: ");
- //Calculate quotient here
- //Calculate any remainder here
- return 0;
- }//end main
- Problem #5 (Shifty Business)
- Compose a program that declares a defined literal value of 9876543201 called ALONGNBR.
- Now you will add printf() statements to manipulate the value stored to accomplish shifting
- to the right, the left and to return rightmost values, printing them to output. The first
- printf() statement will use the division operator to shift the defined number to the right 4
- places, effectively truncating the 3201 values. The second printf() statement should use the
- modulo operator to return the 2 right most values form the defined number. The last
- printf() statement should use the multiplication operator to shift the number two places to
- the left. When you print out the last statement your format modifier should use %lld for a
- long long integer.
- (See Picture)
- Problem #6 A rounding program
- Compose a program that will take a floating point number as input and will round the
- number to the hundredth place of accuracy, rounding up. So if the user enters in the value
- 2.345 the program will round the number to 2.35 and output it to the screen. You should
- use shifting to accomplish your task. First design the algorithm that your program must
- perform to accomplish the task. Now program it, using print statements as needed to verify
- your answers if need be for troubleshooting. Hint: My solution involves moving the
- values to the left, performing a conversion (cast) to int, then shifting the number
- back to the right and converting it back to a floating point data type. NOTE: printing a
- value to screen can round the output as its presented, but the actual value in
- memory that is being used for math operations is not rounded, which can cause
- errors hidden by the rounded output.
Add Comment
Please, Sign In to add comment