Input an integer value in any format (decimal, octal or hexadecimal) using '%i' in C
We know that the decimal, octal, and hexadecimal value can be read through scanf() using "%d", "%o" and "%x" format specifier respectively.
- "%d" is used to input decimal value
- "%o" is used to input integer value in an octal format
- "%x" is used to input integer value in hexadecimal format
But, there is the best way to read the integer value in any format from decimal, octal and hexadecimal - there is no need to use different format specifiers. We can use "%i" instead of using "%d", "%o" and "%x".
"%i" format specifier
It is used to read an integer value in decimal, octal or hexadecimal value.
- To input value in decimal format - just write the value in the decimal format, example: 255
- To input value in octal format - just write the value in octal format followed by "0", example: 03377
- To input value in hexadecimal format – just write the value in hexadecimal format followed by "0x", example: 0xff
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer