C Tutorial/Data Type/int Display

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Displaying Integer Data Types with printf: %d

<source lang="cpp">#include <stdio.h> main(){

   int operand1;
   operand1 = 29;
   printf("The value of operand1 is %d", operand1);

}</source>

The value of operand1 is 29

Printing integers right-justified

<source lang="cpp">#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;

}</source>

1
  12
 123
1234
12345
  -1
 -12
-123
-1234
-12345