大数阶乘

#include<iostream>
#include<stack>
#include<fstream>
using namespace std;
struct Node
{
    int i;
    Node *next;
};
Node *createNode()
{
    Node *node=new Node;
    node->i=0;
    node->next=NULL;
    return node;
}
Node* MulLink(Node *head,int i)
{
    Node *p=head;
    head->i=1;
    p=head;
    int temp=0;
    for(int j=1;j<=i;j++)
    {
        while(p)
        {
            p->i*=j;
   p->i+=temp;
            if(p->i>9)
{
temp=p->i/10;
if(!p->next)
p->next=createNode();
p->i%=10;
p=p->next;
}
else
{
temp=0;
p=p->next;
}
}
p=head;
    }
    return head;
}
void displayLink(Node *head)      
{
    fstream outfile;
    stack<int> display;
    outfile.open("example.txt",ios::out|ios::ate);
    while(head)
    {
display.push(head->i);
         head=head->next;
    }
while(!display.empty())
{
cout<<display.top();
outfile<<display.top();
display.pop();
}
cout<<endl;
}
void freeLink(Node *head)       
{
    Node *p=head;
    while(p)
    {
        head=p->next;
        delete p;
        p=head;
    }
}
int main(int argc,char *argv[])
{
    int n;
    cout<<"Please input the number"<<endl;
    cin>>n;
    Node *head=createNode();
    MulLink(head,n);
    displayLink(head);
    freeLink(head);
    system("PAUSE");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值