如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
#include<stdio.h>#include<malloc.h>#definefalse0#definetrue1structseqstack{intmaxnum;intt;char*s;};typedefstructseqstack*pseqstack;pseqstackcreateemptystack_seq(intm){pseqstackstack=(pseqstack)malloc(sizeof(structseqstack));if(stack!=NULL){stack->s=(char*)malloc(sizeof(char)*m);if(stack->s){stack->maxnum=m;stack->t=-1;returnstack;}elsefree(stack);}printf("outofspace!!\n");returnNULL;}intisemptystack_seq(pseqstackpastack){return(pastack->t==-1);}chartop_seq(pseqstackpastack){if(pastack->t==-1)printf("itisempty!\n");elsereturn(pastack->s[pastack->t]);}voidpush_seq(pseqstackpastack,charx){if(pastack->t>=(pastack->maxnum)-1)printf("overflow!\n");else{pastack->t=pastack->t+1;pastack->s[pastack->t]=x;}}voidpop_seq(pseqstackpastack){if(pastack->t==-1)printf("underflow!\n");elsepastack->t=pastack->t-1;}intnfact(intn){intres;pseqstackst;st=createemptystack_seq(n);while(n>0){push_seq(st,n);n=n-1;}res=1;while(!isemptystack_seq(st)){res=res*top_seq(st);pop_seq(st);}free(st);returnres;}main(){intn;yunsuan:printf("请输入要计算的n:");scanf("%d",&n);printf("则%d!的结果是:%d\n",n,nfact(n));}