Using printf to give the output as precise as the input?

Viewed 393

I want to write a code where output will be as precise as the input. Consider if I executed

scanf("%f", &n);
printf("%f", n);

And if I give 1.2 as an input, it should output 1.2 but it outputs 1.200000. It should be same with integers too, if I give 9 as input, it should only output 9, not 9.00. Is there any way I can do this?

4 Answers
Related