The Code is as follows:
Note:
1. p48 page algorithm 3.1
2. Add this code segment to "data structure (Yan Weimin) sequence stack ".
If any non-negative decimal integer is input, print the number of octal equal to its value.
Void conversion ()/* algorithm 3.1 */
{Sqstack S;
Unsigned N;/* non-negative integer */
Selemtype E;
Initstack (& S);/* initialize stack */
Printf ("N (> = 0) = ");
Scanf ("% u", & N);/* enter a non-negative decimal integer N */
While (N)/* WHEN n is not equal to 0 */
{
Push (& S, N % 8);/* The number of the N in the inbound stack divided by the remainder of 8 (the low position in the octal System )*/
N = N/8;
}
While (! Stackempty (s)/* When the stack is not empty */
{
Pop (& S, & E);/* the top element of the stack is displayed and assigned to E */
Printf ("% d", e);/* Output E */
}
Printf ("/N ");
}
For any non-negative decimal integer input, print the hexadecimal number equivalent to the output value.
Void conversion ()
{Sqstack S;
Unsigned N;/* non-negative integer */
Selemtype E;
Initstack (& S);/* initialize stack */
Printf ("N (> = 0) = ");
Scanf ("% u", & N);/* enter a non-negative decimal integer N */
While (N)/* WHEN n is not equal to 0 */
{
Push (& S, N % 16);/* the remainder of inbound stack n divided by 16 (low position in hexadecimal mode )*/
N = N/16;
}
While (! Stackempty (s)/* When the stack is not empty */
{
Pop (& S, & E);/* the top element of the stack is displayed and assigned to E */
If (E <= 9)
Printf ("% d", e );
Else
Printf ("% C", e + 55 );
}
Printf ("/N ");
}