二級(jí)考試C++輔導(dǎo):大數(shù)的階乘算法

字號(hào):

#include "stdafx.h"
    #include "stdio.h"
    #include "iostream.h"
    int main(int argc, char* argv[])
    {
    int carry,n,j;
    int a[2000];
    int digit=1;
    int temp,i;
    cout<<"please enter n:"<    cin>>n;
    a[0]=1;
    for(i=2; i<=n; i++)
    {
    for(carry=0,j=1; j<=digit; ++j)
    {
    temp=a[j-1]*i+carry;
    a[j-1]=temp%10;
    carry=temp/10;
    }
    while(carry)
    {
    //digit++;
    a[++digit-1]=carry%10;
    carry/=10;
    }
    }
    cout<<"the result is:"<    for(int k=digit; k>=1; --k)
    cout<  cout<    return 0;
    }