#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;
}
#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;
}