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

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

View Full Document Right Arrow Icon
4. EXPRESSIONS
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
/* 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; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Arithmetic Operators The arithmetic operators are: + unary plus - unary minus + addition - subtraction * multiplication / division % remainder (modulus)
Background image of page 4
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>
Background image of page 5

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

View Full DocumentRight Arrow Icon
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)
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 21

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online