该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
调整格式
#include
#include
#define Max_n 10000
typedef struct fx{int fn;
struct fx *last;
struct fx *next;}fx;
int input(void);
fx* csfx(void);
void js(int,int,fx*);
void output(fx *,int);
int main()
{int n,jws;
fx *p;
n=input();
jws=n>1000?Max_n:n>100?Max_n*10:n>10?Max_n*100:Max_n*1000;
p=csfx();
p->fn=1;
js(n,jws,p);
output(p,jws);
system("pause");
}
int input(void)
{int tn;
while(printf("请输入一个<=%d得数",Max_n),scanf("%d",&tn)!=1||tn<1||tn>10000)
{while(getchar()!='\n');
printf("输入错误!\n");
}
return tn;
}
fx* csfx(void)
{fx *tp;
tp=(fx*)malloc(sizeof(fx));
tp->fn=0;
tp->last=NULL;
tp->next=NULL;
return tp;
}
void js(int tn,int jws,fx *p)
{int i;
fx *tp;
tp=p;
for(i=1;i<=tn;i++)
{
p=tp;
while(p!=NULL)
{p->fn*=i;
p=p->next;
}
p=tp;
while(p->next!=NULL)
{
p->next->fn+=p->fn/jws;
p->fn%=jws;
p=p->next;
}
if(p->fn>=jws)
{p->next=csfx();
p->next->last=p;
p->next->fn+=p->fn/jws;
p->fn%=jws;
}
}
}
void output(fx *p,int jws)
{fx *tp;
while(p->next!=NULL)
p=p->next;
printf("%d",p->fn);
tp=p;
p=p->last;
free(tp);
while(p!=NULL)
{printf("%0*d",jws==Max_n?4:jws==Max_n*10?5:jws==Max_n*100?6:7,p->fn);
tp=p;
p=p->last;
free(tp);
}
}