Q:

Input float value and print it with specified digit after decimal point in C

0

Input float value and print it with specified digit after decimal point in C

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# include <stdio.h>

int main ()
{
	float value;	

	printf("Enter float value: ");
	scanf("%f", &value);

	//print without decimal point 
	printf("%0.0f\n", value);
	//print 1 digits after decimal point
	printf("%0.1f\n", value) ;
	//print 2 digits after decimal point 
	printf("%0.2f\n", value) ;
	//print 4 digits after decimal point 
	printf("%0.4f\n", value);

	return 0;
}

Output

Enter float value: 1.234567
1
1.2
1.23
1.2346

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now