Lab 3: Simple Arithmetic


Introduce C Programming Data Types and Operators

Creating a New Folder for lab 3

Following the technique you practiced last week, create a new project named lab 3 in your cpre185labs folder on the U: drive
Problem 1: Mysterious Output

Download the following example source code. Compile and run the program. Using the material that we reviewed in lecture this week, describe the reason behind each of the incorrect program outputs. In each case, a unique error has been made when using the printf() display function. Pay close attention – these mistakes are often pitfalls in later labs! For your lab report, show a corrected program and explain the erroneous output.

Problem 2: Simple Arithmetic

Create a short program that performs the following arithmetic operations and displays the calculation and results to the screen. All calculations should be performed and assigned to an appropriate variable of the specified type. In other words, the arithmetic problem int = 1+2 would be performed by the following piece of code:
int answer; answer = 1 + 2;

Write a single program (“lab3-2.c”) to perform all of the following arithmetic operations. Be sure to pay special attention to the sample output format. All doubles must be displayed to two decimal places, and ints should be outputted as whole numbers.
a. b. c. d. e. f. g. h. i. j. k. l. m. n. int = 6427 + 1725 int = (6971 * 3925) – 95 double = 79 + 12 / 5 double = 3640.0 / 107.9 int = (22 / 3) * 3 int = 22 / (3 * 3) double = 22 / (3 * 3) double = 22 / 3 * 3 double = (22.0 / 3) * 3.0 int = 22.0 / (3.0 * 3.0) double = 22.0 / 3.0 * 3.0 Calculate the area of a circle with circumference 23.567 Convert 14 feet to meters. Convert 76 degrees Fahrenheit to Centigrade.

Sample Program Output:

/wiiwrap /A |. Are the displayed results as you expect in every instance? Capture the output into a text file using the “>” trick on the command line. and while one lab partner drops the wiimote into the other’s hands from a distance. For each case where the output differs from the correct arithmetic result.c to an executable named mag.) through (k. while you are moving it. review the output of your program paying particular attention to arithmetic problems (a. and an explanation in your lab report. Problem 3: Wiimote Download http://www. Run .00 = 47.).1 + 2 = 3 45. Be sure to logoff before leaving your workstation in the lab! Hints 1 ft = 0.8 . Ending the Lab Session Be sure to share your code and output files with your partner.iastate.32) / 1. Include the output.ece. Explain the source code and how the expression computed in the printf line could be useful in interpreting wiimote outputs./mag Compare magnitudes when the wiimote is at rest. explain the C program output.3048 m TC = (TF .30 m After completion.c Compile lab3-3.00 + 1 ft = 0. (you may need to add “-lm” to the gcc command line) Copy over wiiwrap to your directory.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.