Demo entry 6771882

E1_factorial

   

Submitted by anonymous on Nov 22, 2018 at 10:37
Language: C++. Code size: 557 Bytes.

#include <iostream>

using namespace std;

int main()
{
    int n, i, j, c;
    int s[10000] = {0}; //10000位时最多算到3249
    cout<<"请输入一个正整数N:";
    cin>>n;
    s[0] = 1;
    c = 0;
    for(i=1; i<=n; i++)
        for(j=0; j<10000; j++){
            s[j] = s[j] * i + c;
            c = s[j] / 10;
            s[j] = s[j] % 10;
        }
    if(c){
        cout<<"Overflow!"<<endl;
    }
    else{
        i = 9999;
        while(s[i] == 0)
            i --;
        for(; i>=0; i--)
            cout<<s[i];
    }
    return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).