Home > Back-end >  Data structure, use the stack operation to realize the hexadecimal conversion
Data structure, use the stack operation to realize the hexadecimal conversion

Time:09-21

Data structure - a decimal turn N into the system (with the stack to achieve)
Any a non-negative decimal integer input, output requirements and its equivalent octal number (request order stack is used to implement, and stack initialization, stack operation, the stack operation, whether the stack is empty),

CodePudding user response:

//decimal conversion for arbitrary hexadecimal source
#include
using namespace std;

Int main ()
{
Long n;
Int p, c, m=0, s [100].
Cout<& lt;" Input to convert the Numbers: "& lt; Cin> n;
Cout<& lt;" Input to convert hexadecimal: "& lt; Cin> p;

Cout<& lt;" (" & lt;
While (n!=0)//system transformation, the result is deposited in the array s [m]
{
C=n % p;
N=n/p;
m++; S [m]=c;//the remainder in sequence in the array s [m]
}

For (int k=m; K>=1; K -)//output transformed sequence
{
If (s [k] & gt;=10)//for hexadecimal output corresponding letter
Cout<(char) [k] + 55 (s);
The else//or direct digital output
Cout}

Cout<& lt;" ) "& lt;
return 0;
}
  • Related