{`This is one of the very important topics, when special Formatting is required.
Integer Formatting:
By default %d will display output aligned to left.
Using – sign with %d, will display output aligned to right.
Let us illustrate this and other integer formatting by an example:
/* Program to illustrate integer output formatting */
#include <stdio.h>
int main()
{
//int a;
printf(“Enter an integer: ”);
scanf(“%d”,&a);
printf(“\n This is left aligned with spaces in left having total char 8: %8d”,a);
printf(“\n This is right aligned with spaces in right: %-8d”,a);
printf(“\n This is left aligned with zeroes in left of total char 8: %.8d”,a);
return;
}`}
Run this program and see the output you get.
Formatting Of Float:
%f | By default float has precision of 6 digits |
%.3f | 3 digits of precision |
%8.2f | 2 digits of precision with total 8 chars, aligned to left and having zeroes |