Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: How do I print a floating-point number with higher precision say 23.34568734 with only precision up to two decimal places?

Answer: This can be achieved through the use of suppression char '*' in the format string of printf( ) as shown in the following program.
main( )
{
int i = 2 ;
float f = 23.34568734 ;
printf ( "%.*f", i, f ) ;
}
The output of the above program would be 23.35.

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook