There is some kind on imprecision when it comes to printing out of values of addition in decimals with many points of precision.
While printing out the values of addition of 2 floats till 17 digits of precision, it leads to incorrect answer.
// Using floating point numbers,
// prove that
// 0.1 + 0.2 = 0.3
// BONUS POINTS if you use 17 digits of accuracy
// 3 failures accepted
#include <stdio.h>
int main(int argc, char const *argv[])
{
float a, b, c;
a = 0.1;
b = 0.2;
c = a + b;
printf("%0.17f", c);
return 0;
}
The result comes out to be, [Output of addition with float variable type] (https://i.stack.imgur.com/em7px.png)
even, if I use a double variable type,
#include <stdio.h>
int main(int argc, char const *argv[])
{
double a, b, c;
a = 0.1;
b = 0.2;
c = a + b;
printf("%0.17f", c);
return 0;
}
The result comes out to be Output of addition with double variable type