C++实现大数阶乘

  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "iostream.h"
  4. int main(int argc, char* argv[])
  5. {
  6.     int carry,n,j;
  7.     int a[2000];
  8.     int digit=1;
  9.     int temp,i;
  10.     cout<<"please enter n:"<<endl;
  11.     cin>>n;
  12.     a[0]=1;
  13.     for(i=2; i<=n; i++)
  14.     {
  15.         for(carry=0,j=1; j<=digit; ++j)
  16.         {
  17.             temp=a[j-1]*i+carry;
  18.             a[j-1]=temp%10;
  19.             carry=temp/10;
  20.         }
  21.         while(carry)
  22.         {
  23.             //digit++;
  24.             a[++digit-1]=carry%10;
  25.             carry/=10;
  26.         }
  27.     }
  28.     cout<<"the result is:"<<endl;
  29.     for(int k=digit; k>=1; --k)
  30.         cout<<a[k-1];
  31.     cout<<endl;
  32.     return 0;
  33. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值