L4 - 4 EXPRESSIONS Display the value of pi 3.14159265 to 5...

This preview shows pages 1–7. Sign up to view the full content.

4. EXPRESSIONS

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Display the value of pi, 3.14159265 to 5 decimal places, right justified, in 9 columns Read in someone’s height in feet and inches using a single quotation mark for feet and double quotation mark for inches and prints the person’s height in centimeters to two decimal places
/* Computes a Universal Product Code check digit */ #include <stdio.h> int main(void) { int d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5, first_sum, second_sum, total; printf("Enter the first (single) digit: "); scanf("%1d", &d); printf("Enter first group of five digits: "); scanf("%1d%1d%1d%1d %1d", &i1, &i2, &i3, &i4, &i5); printf("Enter second group of five digits: "); scanf("%1d%1d%1d%1d %1d", &j1, &j2, &j3, &j4, &j5); first_sum = d + i2 + i4 + j1 + j3 + j5; second_sum = i1 + i3 + i5 + j2 + j4; total = 3 * first_sum + second_sum; printf("Check digit: %d\n", 9 - ((total - 1) % 10)); return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Arithmetic Operators The arithmetic operators are: + unary plus - unary minus + addition - subtraction * multiplication / division % remainder (modulus)
Arithmetic Operators The value of i % j is the remainder when i is divided by j . For example, the value of 10 % 3 is 1; the value of 12 % 4 is 0 . The % operator requires integer operands; all other operators allow either integer or floating-point operands. If both operands are integers, / truncates the result toward 0 . There is no exponentiation operator. Must use “pow” function defined in <math.h>

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Operator Precedence When an expression contains more than one operator, the meaning of the expression may not be immediately clear: Does i + j * k mean (i + j) * k or i + (j * k)
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/08/2011 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.

Page1 / 21

L4 - 4 EXPRESSIONS Display the value of pi 3.14159265 to 5...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online