by Dinesh Thakur
		

#include <stdio.h>

void main()
{
   double PI = 3.141595358979;
   float A= 7.5;
   int K = 456;
   clrscr();
   printf("Display some values in separate lines.\n");
   printf("PI = %lf\nA = %f\n", PI,A);
   printf("K (in decimal) = %d\n", K);
   printf("K (in octal) = %0\n", K);
   printf("K (in hexadecimal) = %x\n", K);
   printf("K (in hexadecimal cap. letters) = %X\n", K);
   printf("Display some values in same line.\n");
   printf("PI = %G,\t A = %%%f,\t K = %d\n", PI, A, K);
}

The expected output is as given below.

    Write Program to Read in an INT and then Print in out DEC, OCT and HEX

Explanation of the output: The second and third lines of the output are due to the print statement.

printf("PI = %lf\n A = %f\n", PI,A);

Here, "PI = " is a text segment which is displayed as it is written in the above statement. The value of PI is displayed where % l f appears. Then comes "\ n" which takes the cursor to the next line; so, "A= " is displayed in the next line. After this, the value of A is displayed where %f appears. Again we have used"\n" so that other outputs are shifted to the next line. The fourth line of the output is the usual output statement for an integer. The statement between parentheses "in decimal" indicates number with base 10. Value of Kin decimal system is 456 as declared in the program. The next two lines of the output display the same value 456 converted into octal (base 8) and hexadecimal (base 16) system. This is achieved by simply changing the conversion character after% sign. For octal, the sign used is "o", while for hexadecimal "x" may be used if character digits of hexadecimal system are desired in lowercase and "X" for the character digits to be displayed in uppercase (capital letters). The last line of the output displays several values in the same line separated by spaces and commas. For displaying the percent sign% with 7.5, we have to put an extra symbol"%%" in the formatting string, i.e., the code becomes "A= %%%f". becomes "A= %%%f".