Q:

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

belongs to collection: C scanf() Programs

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)

Input an unsigned integer value using scanf() in C... >>
<< Input an integer value and print with padding by Z...