Skip to content
Home » C Program to Display Equivalent Octal and Hexadecimal Value

C Program to Display Equivalent Octal and Hexadecimal Value

Learn about C Program to Display Equivalent Octal and Hexadecimal Value in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program to Display Equivalent Octal and Hexadecimal Value

Using the printf() function in the C programming language, this code snippet will print an entered value in Decimal, Octal, and Hexadecimal format. We can print the value in the desired format by using different format specifiers.

  • %d – display value in integer format
  • %o – display value in octal format
  • %x – diplay value in hexadecimal format

Program:

#include<stdio.h>
int main()
{
  int num;

  printf("Enter a number: ");
  scanf("%d",&num);

  printf("Octal Value = %o\n",num);
  printf("Hexadecimal Value = %X\n",num);

  return 0;
}

Output:

Enter a number: 25
Octal Value = 31
Hexadecimal Value = 19

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Three-Digit Integer Number in Reverse Order
C Program to Find Area and Volume of a Cylinder