Cherry blossoms

xiaoxiao2021-03-06  79

Just wrote a lot of questions, let's take a look.

#include #define maxsize 32typedef struct {int * elem; int max; int top;} stack;

INT INITSTACK (Stack * S, INT N) {S-> ELEM = (int *) malloc (n * sizeof (int)); if (S-> elem == null) return -1; s-> max = n ; S-> TOP = 0; return 0;}

INT Push (stack * s, int item) {if (S-> TOP == S-> max) {printf ("stack is full! / n"); return -1;} S-> ELEM [S-> TOP ] = item; return 0;} int stackempty (stack s) {return ((! s.top)? 1: 0);}

INT POP (stack * s) {if (! S-> TOP) {Printf ("Pop An Empty Stack! / N"); Return -1;} Return S-> ELEM [- S-> TOP];

Void MultibaseOutput (long n, int b) {INT M; Stack S; IF (INITSTACK (& S, MaxSize) {Printf ("Failure! / N"); return;} do {ix (Push (& S, N% B) )) {Printf ("failure! / N"); return;} n = n / b;} while (n! = 0); while (! Stackempty (s)) {m = POP (& s); if (M <10) Printf ("% d", m); Else Printf ("% C", M 55);

}

#include long atoi (char s [], int b) {INT I, N;

n = 0; for (i = 0; s [i]> = '0' && s [i] <= '9'; i) n = b * n (S [i] - '0'); return N;

Main () {Long M, B1, B2; INT i = 0; Char C; Char * SM, * SB1, * SB2;

Printf ("a $ ="); for (c = getchar (); c! = '<'; c = getChar ()) SM [i ] = C; SM [i] = '/ 0';

For (c = getchar (), i = 0; c! = '>'; c = getChar ()) SB1 [i ] = C; SB1 [i] = '/ 0'; for (c = getchar (), i = 0; c! = '/ n'; c = getChar ()) SB2 [i ] = C; SB2 [i] = '/ 0';

B1 = ATOI (SB1, 10); B2 = ATOI (SB2, 10); M = ATOI (SM, B1); Printf ("% S <% S>% S =", SM, SB1, SB2); Multibaseoutput M, B2); Printf ("<% ld>", b2); getCH ();

}

Surrounded by the comment, debugging under WINTC

More than I am not light :)

转载请注明原文地址:https://www.9cbs.com/read-101619.html

New Post(0)