Display integers in octal or hexadecimal format using %o and %x, respectively. - C Language Basics

C examples for Language Basics:printf

Introduction

You can display integers in octal or hexadecimal format using %o and %x, respectively.

For uppercase hexadecimal format, use the %X format specifier; for lowercase, use %x, as shown here:

Demo Code

#include <stdio.h>

int main(void)
{
   unsigned num;//from w ww  .j  a v  a2  s .c om

   for (num = 0; num < 16; num++) {
      printf("%o ", num);
      printf("%x ", num);
      printf("%X\n", num);
   }

   return 0;
}

Result


Related Tutorials