#include <stdio.h>
int main() {
float k;
scanf("%f", &k);
printf("%f", k);
}
In this simple program when I enter a number containing at most 8 digits then it is displayed correctly.
But if I exceed 8 digits i.e. for the input 123456789
the output is 123456792
.
Why this is happening? Well the fun fact is that if I enter any number between 123456789
and 123456796
then it always shows 123456792
.
Is it something related to the 8 decimal precision of floating numbers?