[原创] 高阶阶乘源码
// 高阶阶乘.cpp : 定义控制台应用程序的入口点。//
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct Node{
long data;
struct Node *prior;
struct Node *next;
} Node;
const long N=10000;
int _tmain(int argc, _TCHAR* argv[])
{
Node a,*Head,*p,*Last;
a.data=1;a.next=NULL;a.prior=NULL;
Head=&a;p=Head;
long carry=0,Mutl=0;
for(long i=1;i<=N;i++){
p=Head;
while(p){
Mutl=p->data*i+carry;
carry=Mutl>10000?Mutl/10000:0;
p->data=carry?Mutl%10000:Mutl;
Last=p;p=p->next ;
};
//若有进位则需要增加链表长度
if(carry) {
Node *tmp;
tmp=new Node;
tmp->data=carry;
tmp->next=NULL;
p=Last;p->next=tmp;
tmp->prior=p;
carry=0;
}
}
while(Last){
cout << Last->data;
Last=Last->prior;
}
cout<<endl;
system("PAUSE");
return 0;
}