Answer E20

#include <stdio.h>

/* Puzzle E20 -- math to C */
 
int main()
{
  double x = 12.3, y = 7.2, c = 3.2;
  double result;
  
  result =  (x+y)/(2*c) ;  /* Both sets of () are needed */
  
  printf("result: %f\n", result ); 
  return 0;
}

The first set of () is evaluated: (x+y).

Then the second set is evaluated: (2*c)

Then those two values are divided.

(x+y) /  (2*c)
----
         -----    
      /   

Without the second set of () , the first set is evaluated: (x+y). Then that value is divided by 2, and the resulting value multiplied by c.

(x+y)/2*c
-----
     /2 
-------  
       *c


Back to Puzzle Home