C++实现大数阶乘
来源:互联网 发布:电梯调度算法 java 编辑:程序博客网 时间:2024/06/10 14:00
- #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:"<<endl;
- 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)
- {
-
- a[++digit-1]=carry%10;
- carry/=10;
- }
- }
- cout<<"the result is:"<<endl;
- for(int k=digit; k>=1; --k)
- cout<<a[k-1];
- cout<<endl;
- return 0;
- }