7-15 BCD decryption

7-15 BCD decryption

topic

The BCD number is a byte to express two decimal numbers, and every four bits represent one bit. So if the hexadecimal number of a BCD number is 0x12, it expresses 12 decimal. But Xiaoming never learned BCD, and converted all BCD numbers as binary numbers to decimal output. So 0x12 of BCD is output as decimal 18!

Now, your program must read in the wrong decimal number and then output the correct decimal number. Tip: You can convert 18 back to 0x12 and then back to 12.
Input format:

The input gives a positive integer in the range [0, 153] in a line, which guarantees that it can be converted back to a valid BCD number, that is to say, the number of AF will not appear when this integer is converted into hexadecimal.
Output format:

The corresponding decimal number is output.
Sample input:

18

Sample output:

12

Code

#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int x;
	x=n%16;
	n=n/16*10+x;
	printf("%d",n);
	return 0;
} 
Published 21 original articles · praised 0 · visits 39

Guess you like

Origin blog.csdn.net/weixin_47127378/article/details/105565962