/* Hexadecimal conversion
Problem description
Input a decimal number N and convert it to the r hexadecimal number output.
Input
The input data includes multiple trial instances. Each trial instance includes two integers, n (32-bit integer) and R (2 <= r <= 16, r <> 10 ).
Output
The number of converted outputs for each consumer trial instance. Each output occupies one row. Assume that R is greater than 10, then the corresponding digital rule is taken into hexadecimal notation (for example, 10 is represented by a, and so on ).
Sample Input
7 2
23 12
-4 3
Sample output
111
1B
-11
*/
// Use a two-character array to solve this problem
# Include <stdio. h>
Int main ()
{
Int N, R;
Char A [35];
Char B [] = "0123456789 abcdef ";
While (~ Scanf ("% d", & N, & R ))
{
Int T = 0, I;
If (n <0)
{
Printf ("-");
N = N * (-1 );
}
For (I = 0; I ++) // returns the remainder repeatedly, and finally outputs the array data.
{
A [I] = B [n % R];
T ++;
N = N/R;
If (n = 0)
Break;
}
While (t --)
{
Printf ("% C", a [T]);
}
Printf ("\ n ");
}
While (1 );
Return 0;
}
Carry conversion (hangdian 2031)