Q:

how to Print value in Decimal, Octal, Hexadecimal using printf in C

0

Printing value in Decimal, Octal, Hexadecimal using printf in C

This code snippet will print an entered value in Decimal, Octal and Hexadecimal format using printf() function in C programming language. By using different format specifier we can print the value in specified format.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Print value in Decimal, Octal ad Hex using printf() in C

/*Printing value in Decimal, Octal, Hexadecimal using printf in C.*/
 
#include <stdio.h>
 
int main()
{
    int value=2567;
     
    printf("Decimal value is: %d\n",value);
    printf("Octal value is: %o\n",value);
    printf("Hexadecimal value is (Alphabet in small letters): %x\n",value);
    printf("Hexadecimal value is (Alphabet in capital letters): %X\n",value);
     
    return 0;   
}

Output

    Decimal value is: 2567
    Octal value is: 5007
    Hexadecimal value is (Alphabet in small letters): a07
    Hexadecimal value is (Alphabet in capital letters): A07

Here, following format specifiers are used:

  • %d - to print value in integer format
  • %o - to print value in octal format
  • %x - to print value in hexadecimal format (letters will print in lowercase)
  • %X - to print value in hexadecimal format (letters will print in uppercase)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now