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   

Related Posts:

  • Simple Interest 1 Program#include<stdio.h>#include<conio.h>main(){ int p,t,r,si; clrscr(); printf("enter the values of p,t,r"); scanf("%d%d%d",&p,&t,&r); si=(p*t*r)/100; printf("%d",si); getch();} … Read More
  • Program for Even or Odd/*check even or odd*/#include<stdio.h>#include<conio.h>main(){ int a; clrscr(); printf("enter the value of a"); scanf("%d",&a); if(a%2==0) { printf("%d is even",a); } else printf("%d is odd",a); getch();} … Read More
  • Program for Compound Interest/*programme to cal compound intrest*/#include<stdio.h>#include<conio.h>#include<math.h>main(){ int p,r,n; float ci; printf("enter the values of p,r,n"); scanf("%d%d%d",&p,&r,&n); ci=p*(pow(((1+r)… Read More
  • Program For Switch Case | Example for Switch Case Program #include<stdio.h>#include<conio.h>#include<graphics.h>main(){ int gd=DETECT,gm; int l,m,n,d,e; clrscr(); initgraph(&gd,&gm,"."); gotoxy(12,28); printf("\n\n\n\n\n\n"); printf("\t\t\t"); printf("*****… Read More
  • Program for Traingle#include<stdio.h>#include<conio.h>main(){ int n,i,j,t=1; clrscr(); printf("enter the value:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf("%3d",t); t=t+1; } printf("\n"); } ge… Read More

0 comments:

Post a Comment