題目1076:N的階乘

來源:互聯網
上載者:User

標籤:online judge   九度   編程   c++   

題目描述:

 輸入一個正整數N,輸出N的階乘。

輸入:

正整數N(0<=N<=1000)

輸出:

 輸入可能包括多組資料,對於每一組輸入資料,輸出N的階乘

範例輸入:
4515
範例輸出:
241201307674368000
來源:

2006年清華大學電腦研究生機試真題

#include <iostream>#include <string.h>#include <stdio.h>//不逾時的代碼using namespace std; int main(){    int N;    int num[3001];    while(cin >>N)    {        int i,j,k;        memset(num,0,sizeof(num));        num[0] = 1;        int length = 1;        if(N == 0)        {            cout << 1 <<endl;            continue;        }        for(i = 1; i<=N ; i++)        {            int over = 0;             for(j = 0; j < length; j++)            {                num[j] = num[j] * i + over;                if(num[j] >= 10)                {                    over = num[j] / 10;                    num[j]  = num[j] % 10;                }                else                    over = 0;            }            while(over != 0)            {                int temp = over % 10;                num[length ++] = temp;                over = over / 10;            }         }        for(i = 3000;i >=0 ; i--)            if(num[i] != 0)                break;        for(j = i ; j >= 0 ; j--)            cout<<num[j];        cout << endl;    }    return 0;}/**************************************************************    Problem: 1076    User: Carvin    Language: C++    Result: Accepted    Time:1320 ms    Memory:1520 kb****************************************************************/


題目1076:N的階乘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.