#include<stdio.h>
#include<conio.h>
int main()
{
float g=123.456789;
printf("\n %.1f",g);
printf("\n %.2f",g);
printf("\n %.3f",g);
printf("\n %.4f",g);
getch();
}
This program demonstrates the use of precision specifiers.
The program initializes a float variable g
with a value of 123.456789. Then it uses the printf function to display the value of g
with different levels of precision.
The precision is specified by adding a dot .
and a number after the field width in the format string. For example, %.1f
specifies one digit of precision after the decimal point.
The program displays the value of g
with precision of 1, 2, 3, and 4 decimal places. The output will be:
123.5
123.46
123.457
123.4568
The value is rounded to the specified number of decimal places.
Thanks
Write a program to demonstrate the use of precision specifiers