Printing integers right-justified : int Display « Data Type « C Tutorial






#include <stdio.h>

int main()
{ 
   printf( "%4d\n", 1 );
   printf( "%4d\n", 12 );
   printf( "%4d\n", 123 );
   printf( "%4d\n", 1234 );
   printf( "%4d\n\n", 12345 ); 

   printf( "%4d\n", -1 );
   printf( "%4d\n", -12 );
   printf( "%4d\n", -123 );
   printf( "%4d\n", -1234 );
   printf( "%4d\n", -12345 );

   return 0;

}
1
  12
 123
1234
12345

  -1
 -12
-123
-1234
-12345








2.4.int Display
2.4.1.Displaying Integer Data Types with printf: %d
2.4.2.Printing integers right-justified