Working with Arithmetic Expressions 33
is evaluated according to the rules stated previously as
(a b) + (c d)
or
(100 2) + (25 4)
The result of 300 is handed to the printfroutine.
Integer Arithmetic and the Unary Minus Operator
Program 4.3 reinforces what you just learned and introduces the concept of integer
arithmetic.
Program 4.3 More Examples with Arithmetic Operators
// More arithmetic expressions
#include <stdio.h>
int main (void)
{
int a = 25;
int b = 2;
float c = 25.0;
float d = 2.0;
printf ("6 + a / 5 * b = %i\n", 6 + a / 5 * b);
printf ("a / b * b = %i\n", a / b * b);
printf ("c / d * d = %f\n", c / d * d);
printf ("-a = %i\n", -a);
return 0;
}
Program 4.3 Output
6 + a / 5 b = 16
a / b b = 24
c / d * d = 25.000000
-a = -25
Extra blank spaces are inserted between intand the declaration of a,b,c,and din the
first four statements to align the declaration of each variable.This helps make the pro-
gram more readable.You also might have noticed in each program presented thus far that
a blank space was placed around each operator.This, too, is not required and is done