|
#include <iostream.h>
#include <iomanip.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int getN();
int getBitNum(int n);
char *init(int size);
void calc(char *a,int n);
void display(char *a,int size);
/*-------------------------------*/
void main(void)
{
int n=getN();
int size=getBitNum(n);
char *pa=init(size);
calc(pa,n);
display(pa,size);
delete []pa;
}
/*-------------------------------*/
int getN()
{
int n;
printf("请输入n!中的n:");
cin>>n;
while(n<0)
{
printf("输入有错误,请重新输入:");
cin>>n;
}
if(n==0)
exit(1);
return n;
}
/*-------------------------------*/
int getBitNum(int n)
{
double sum=1.0;
int i=1;
for(;i<=n;i++)
sum+=log10(i);
return (int)sum;
}
/*-------------------------------*/
char *init(int size)
{
char *pa=new char[size];
if(!pa)
{
printf("too large factor of %d\n",size);
exit(1);
}
pa[0]=1;
int i=1;
for(;i<size;i++)
pa[i]=0;
return pa;
}
/*-------------------------------*/
void calc(char*a,int n)
{
double bitcount=1;
int begin=0;
int i=2;
for(;i<=n;i++)
{
long and=0;
bitcount+=log10(i);
if(a[begin]==0)
begin++;
int j=begin;
for(;j<(int)bitcount;j++)
{
and+=i*a[j];
a[j]=char(and%10);
and/=10;
}
}
}
/*-------------------------------*/
void display(char*a,int size)
{
int bit=0;
int i=size-1;
for(;i>=0;i--)
{
if(bit%68==0)
cout<<"第"<<setw(3)<<(bit/50+1)<<"个68位:";
cout<<(int)a[i];
bit++;
}
cout<<endl;
}
/*-------------------------------*/ |
|