Below is the solution code for an excercise from KN King\'s Modern Programming approach.
#include
int main(void)
{
int i;
float j,x;
Why are there extra decimal values seen for floats?
That's why floats are floats.By default %f lets you display 6 digits after decimal. That's nothing do do with the precision of the number stored.Numbers are stored according to the IEEE 754 FLOATING POINT representation in most systems.And numbers are not stored with decimal points. So, since you do not control how you store numbers, you can't change the precision.Precision is fixed.
Is there any default precision set for float and how can I change it.
Again , precision is not default its not how it is stored. Check its representation for 32 bit or 64 bit.Youwould like to print more/less digits after decimal.You can do this :
float i=2.89674534423;
printf("%.10f",i); Prints 10 digits after decimal.