# include & lt; iostream>
using namespace std;
The class stack {
Private:
Int maxsize;
int top;
Int * st2;
Public:
~ the stack ()
{
The delete [] st2;
}
The stack (int size)
{
Maxsize=size;
St2=new int [maxsize];
Top=1;
}
Void push (int num)
{
St2 [+ + top]=num;
}
Void the pop ()
{
Int item;
While (top!=1) {
The item=st2 [top --];
cout}
}
};
/*
TODO: design algorithm is used to convert a decimal integer to between 2 to 9 into the system of arbitrary hexadecimal number output,
Among them, n to convert decimal integer, m as the base, the values of 2 to 9,
Tip: the stack to address
*/
Void Binaryconv (int n, int m)//hexadecimal conversion
{
Stack s (32);
Int a=n, b=0;
While (a & gt; 0)
{
A=n;
B=a % m;
A=a/m;
Supachai panitchpakdi ush (b);
}
cout <"Integer" & lt;Supachai panitchpakdi op ();
}
Int main ()
{
Int n, m;
Cin & gt;> n;
Cin & gt;> m;
Binaryconv (n, m);
return 0;
}
CodePudding user response:
While (a & gt; 0){
A=n;
B=a % m;
A=a/m;
Supachai panitchpakdi ush (b);
}
N the same
Is a constant
The a/m constant
The infinite loop
The infinite push
The cross-border
Will cause abnormal
CodePudding user response:
Oh missed m unchangedCodePudding user response:
while (a & gt; 0)
{
A=n;//why this statement assignment here, outside while already assignment, because n without modification, so every time a initial value will be an assignment, this will result in infinite loop,
B=a % m;
A=a/m;
Supachai panitchpakdi ush (b);
}
CodePudding user response: