C examples for Language Basics:printf
Control field width for a single integer in output
#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; }