Answer:
Written in C++
#include <stdio.h>
int main(){
double value = 9876.12345;
printf("1: %.1g\n", value);
printf("2: %.2g\n", value);
printf("3: %.3g\n", value);
printf("4: %.4g\n", value);
printf("5: %.5g\n", value);
printf("6: %.6g\n", value);
printf("7: %.7g\n", value);
printf("8: %.8g\n", value);
printf("9: %.9g\n", value);
return 0;
}
Explanation:
This declares and initializes value as double
double value = 9876.12345;
This prints the first precision
printf("1: %.1g\n", value);
This prints the second
printf("2: %.2g\n", value);
This prints the third
printf("3: %.3g\n", value);
This prints the fourth
printf("4: %.4g\n", value);
This prints the fifth
printf("5: %.5g\n", value);
This prints the sixth
printf("6: %.6g\n", value);
This prints the seventh
printf("7: %.7g\n", value);
This prints the eight
printf("8: %.8g\n", value);
This prints the ninth
printf("9: %.9g\n", value);
The precision is printed using the following syntax: printf("%.ag\n", value);
Where a represents the number of digits to print