Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
short a;
int b;
long c;

float d;
double e;
double f;

a = 533;
b = 6789;
c = 466438237;

d = a /7;
e=b/30;
f=c/789;

printf("Value of d is %f\n", d);  // Incorrect value of d i.e.     76.000000 is printed
printf("Value of e is %f\n", e);  // Incorrect value of e i.e.    226.000000 is printed
printf("Value of f is %f\n", f);  // Incorrect value of f i.e. 591176.000000 is printed 7; /* d  76.0 */
e= b / 30; /* e is 226.0 */
f = c / 789; /*  f is 591176.0 */

Compliant Code Solution 1

...

Code Block
bgColor#CCCCFF
short a;
int b;
long c;

float d;
double e;
double f;

a=533;
b=6789;
c= = 533;
int b = 6789;
long c = 466438237;

float d = a / 7.0f;
e=b/30.0f;
f=c/789.0f;

printf("Value of /* d is %f\n", d);  // Correct value of d i.e.     76.142860 is printed
printf("Value of e is %f\n", e);  // Correct value of e i.e.    226.300000 is printed
printf("Value of f is %f\n", f);  // Correct value of f i.e. 591176.472750 is printed76.14286 */
double e = b / 30.0f; /* e is 226.3 */
double f = c / 789.0f; /* f is 591176.47275 */

Compliant Code Solution 2

...