Saturday 20 January 2018

Output Of Integer Numbers | practical c programming | general c programs



Output Of Integer Numbers


Output Of Integer Numbers
The format specification for printing an integer number is %wd where w specifies the minimum field width for the output. However if a number is greater than the specified field width,it will be printed in full. Overr iding the minimum specification d specifies the value to be printed is an
 integer.The following examples illustrate the output of the number 9876 under different formates:
          Format                                Output
   printf("%d", 9876)                           9 8 7 6
   printf("%6d",9876)                          S S 9 8 7 6
   printf("%2d",9876)                          9 8 7 6
   printf("%-6d",9876)                        9 8 7  6 S S
   printf("%06d",9876)                       0 0 9 8 7 6

       It is possible to force the printing to be left-justified by placing a minus sign directly after the %
character.




Program: The output of integer number under various formats
     /* printing of integer numbers*/
     main()
     {
      int m=12345;
      long n=987654;
      printf("%d\n",m);
      printf("%10d\n",m);
      printf("%010d\n",m);
      printf("-10d\n",m);
      printf("%10ld\n",n);
      printf("%10ld \n",-n);
     }

output: 12345
                      12345
             000012345
             12345
                     987654
                   - 987654   

0 comments:

Post a Comment