C Program to show different formatting in output using printf

This program shows different output format specifiers present in C programming language. To show a few of its implementation.

  1. Printing without any formatting
  2. Printing preceeding 4 white spaces
  3. Printing with preceeding zeros
  4. Printing integer format (floating point is removed)
  5. Printing integer format with white spaces
  6. Printing value with its exponent
  7. Printing 3 digits before and 2 digits after decimal
  8. Printing lower case exponent
  9. Printing upper case exponent


void main()
	int a, b;
	float c, d, e;
	a = 22;
	printf("Printing without formatting:\t%d\n", a);
	printf("Preceeding four white spaces:\t%4d\n", a);
	printf("Preceeding zeros:\t%04i\n", a);
	b = a / 7;
	printf("Integer format not printing decimal:\t%d\n", b);
	printf("Preceeding three white spaces:\t%3d\n", b);
	c = 26.9;
	d = c / 3;
	printf("Printing value in exponent form:\t%e\n", c);
	printf("Printing 3 digits before and 2 digits after decimal:\t%3.2f\n", d);
	e = 864591234.985461209573;
	printf("Printing exponent in lower case format:\t%g\n", e);
	printf("Printing exponent in upper case format:\t%G\n", e);


Printing without formatting:	22
Preceeding four white spaces:	  22
Preceeding zeros:	0022
Integer format not printing decimal:	3
Preceeding three white spaces:	  3
Printing value in exponent form:	2.690000e+01
Printing 3 digits before and 2 digits after decimal:	8.97
Printing exponent in lower case format:	8.64591e+08
Printing exponent in upper case format:	8.64591E+08