Carry conversion (hangdian 2031)

Source: Internet
Author: User

/* 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.