I would be grateful if somebody could help me with this question.
A C program contains the following declarations and initial assignments.
int i = 8, j = 5;
float x = 0.005, y = - 0.01;
char c = 'c', d = 'd';
Determine the value of the following expression using values assigned to the variables for the expression:
(i - 3 * j) % ( c + 2 *d)/ (x - y )
I tried this manually first:
( i- 3 * j) % ( c + 2 *d ) / ( x - y)
( 8 - 3*5) % ( 99 + 2 * 100 ) / ( 0.005 - (-0.01) )
( -7 ) % ( 299 ) / ( 0.015 )
Keeping precedence and associativity in mind, I used the mod operator first:
( 292 ) / ( 0.015 )
Which gave the answer 19466.66.
This does not match with the answer given in the book or when I used this in codeblocks, both of which gave the answer as - 466.6667
The codeblocks program is as below
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 8,j = 5, c = 'c',d = 'd';
float x = 0.005, y = -0.01, a = 0.0; // a is the float variable to which the value is assigned
a = (i-3*j)%(c+2*d)/(x-y);
printf("%f\n",a);
return 0;
}