Formatting of Integers, Real Numbers and Strings in C


Levels of difficulty: / perform operation:

C Program to format the outputs of Integers, Floats and Strings. Here we gives the all the format specifiers example.

C Program

#include<stdio.h>
#include<conio.h>
void main()
{

	int num1 = 12345;
	long num2 = 987654;
	float num3 = 98.7654;
	clrscr();
	printf("%d\n\n", num1);
	printf("%10d\n\n", num1);
	printf("%010d\n\n", num1);
	printf("%-10d\n\n", num1);
	printf("%10ld\n\n", num2);
	printf("%10ld\n\n", -num2);
	printf("%7.4f\n\n", num3);
	printf("%f\n\n", num3);
	printf("%7.2f\n\n", num3);
	printf("%-7.2f\n\n", num3);
	printf("%07.2f\n\n", num3);
	printf("%*.*f", 7, 2, num3);
	printf("\n\n");
	printf("%10.2e\n\n", num3);
	printf("%12.4e\n\n", -num3);
	printf("%-10.2e\n\n", num3);
	printf("%e\n\n", num3);
	printf(":%s:\n", "Hello, world!");
	printf(":%15s:\n", "Hello, world!");
	printf(":%.10s:\n", "Hello, world!");
	printf(":%-10s:\n", "Hello, world!");
	printf(":%-15s:\n", "Hello, world!");
	printf(":%.15s:\n", "Hello, world!");
	printf(":%15.10s:\n", "Hello, world!");
	printf(":%-15.10s:\n", "Hello, world!");
	getch();
}


Output







Quantitative Aptitude
Reasoning
Programming
Interview