Home > Back-end >  Converting decimal k into the system
Converting decimal k into the system

Time:10-19

#include
Void func (int x, int k);
Int main ()
{
Int x, k;
The scanf (" % d % d ", & amp; X, & amp; K);//enter a decimal x, convert hexadecimal k
Func (x, k);
return 0;
}
Void func (int x, int k)
{
Int a [20], I=0;
While (x/k!=0)//decimal into k into the system, take more method used in addition to the k
{
i++;
A [I]=x % k;//the remainder in array
X=x/k;
}
//a [+ + I]=x;//the last remainder
for(; I>=0; I -)//remainder in reverse order output is the corresponding hexadecimal number
/* {
If (a [I] & gt; 9)
Printf (" % c ", a [I] + 55);//will be bigger than the 9 number into corresponding capital letters, use ASCII A ASCII to 65
The else
Printf (" % d ", a [I]);
} */
Printf (" % ld \ n ", a [I - 1));

}
Why content exists in the annotation, its compilation is right?

CodePudding user response:

If the remainder is more than 9, if it is should be the remainder into another character? , such as hexadecimal, said with A 11 in B, and so on, more than 9 with letters, how to put the remainder into letters of more than 9, showing in the comments
  • Related