[PTA] 7-15 BCD decryption (10 minutes)

BCD number is expressed by one byte, the number of decimal two, each represented by a four bit. So if a hexadecimal BCD number is 0x12, it is the expression of decimal 12. But Xiao Ming never learned BCD, BCD all the numbers are treated as a binary number converted to decimal output. So BCD output of 0x12 is decimal 18 of became!

Now, your program should read this decimal error, and then output the correct number of decimal. Tip: You can convert back to 18 0x12, and then converted back to 12.

Input format:
input given in row a positive integer in the range [0, 153], can be converted back to ensure that the BCD number is valid, that is to say does not occur when the AF digital convert the integer to a hexadecimal.

Output format:
output a corresponding decimal number.

Sample input:
18

Sample output:
12

#include<stdio.h>
int main()
{
    int i;
    scanf("%d",&i);
    printf("%x",i);
    return 0;
}

Tip: Decimal turn hexadecimal output% x

Published 48 original articles · won praise 0 · Views 328

Guess you like

Origin blog.csdn.net/weixin_46399138/article/details/105332559
Recommended