Run and explain the output produced by the following program

Run and explain the output produced by the following program: include int main (void) {float a, b; b = 2.0 e20 + 1.0; a = b - 2.0e20; printf (\"% f\ \", a); return 0;}

Solution

Solution:

#include<stdio.h>
int main(void)
{
   float a,b;
   b= 2.0e20 + 1.0;
   a= b - 2.0e20;
   printf(\"%f\ \", a);
   return 0;
}

Output:
4008175468544.000000

Explanation:

The computer does not keep retain of ample decimal places. The number 2.0e20 is 2 followed by 20 zeros and by adding 1 you are trying to change the 21st digit. To do this correctly, the program would require to store a 21-digit number. A float number is typically just six or seven digits scaled to bigger or smaller numbers with an exponent.

 Run and explain the output produced by the following program: include int main (void) {float a, b; b = 2.0 e20 + 1.0; a = b - 2.0e20; printf (\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site