Control field width for a single integer in output - C Language Basics

C examples for Language Basics:printf

Description

Control field width for a single integer in output

Demo Code

#include <stdio.h>

int main(void){
  int k = 678;//from   ww w  . ja  v a 2  s .  co m

  // Display formats as heading then display the values
  printf("%%d   %%o   %%x   %%X\n");
  printf("%d  %o  %x  %X\n", k, k, k, k );
  printf("\n|%%8d       |%%-8d      |%%+8d      |%%08d      |%%-+8d     |\n");
  printf("|%8d  |%-8d  |%+8d  |%08d  |%-+8d  |\n", k, k, k, k, k );
  return 0;
}

Result


Related Tutorials