注册 登录
编程论坛 C++教室

c++初级编程 求大神指点

linsir 发布于 2013-08-13 10:04, 1018 次点击
长整数四则运算
 【问题描述】设计任意两个长正整数(小于80位)的加法函数add()和乘法函数mult(),并求任意整数(≤58)的阶乘。
【实现提示】用无符号整型或字符型数组存储任意长整数。
【测试数据】
6!=720
9!=362880
19!=1216451004088320000
39!=20397882081197443358640281739902897356800000000
14 回复
#2
rjsp2013-08-13 10:29
哪里不会?
#3
zhengchen0802013-08-13 13:32
是要把这个编出来还是什么
#4
linsir2013-08-15 10:32
回复 3楼 zhengchen080
求编出来,大神
#5
linsir2013-08-15 10:32
回复 2楼 rjsp
哪里都不会
#6
xufan2013-08-15 11:55
我这写了一个,你试试
程序代码:
#include <iostream>
using namespace std;

unsigned int GetMulti(unsigned int);

int main()
{
    unsigned int a;
    cout<<"Enter the number : ";
    cin>>a;
    cout<<GetMulti(a)<<endl;

    return 0;
}

unsigned int GetMulti(unsigned int nCnt)
{
    if (0 == nCnt)    return 1;
   
    return nCnt*GetMulti(nCnt - 1);
}

#7
cs648812792013-08-15 12:48
const long int a=1;
cin>>n;
for(int i=1;i++;i<=n)a=a*i;
cout<<a;
我也是菜鸟.......就想吐槽而已....
#8
peach54602013-08-15 12:58
楼上各位的代码就没发现什么问题?

数字太大,表现不出来啊,大哥大姐们...
#9
xufan2013-08-15 13:43
恩,看到了哦。的确超过了范围
#10
xufan2013-08-15 14:12
我更改了下,应该可以放的下了。
程序代码:
#include <iostream>
using namespace std;

unsigned long long GetMulti(unsigned int);

int main()
{
    unsigned int a;
    cout<<"Enter the number : ";
    cin>>a;
    cout<<GetMulti(a)<<endl;

    return 0;
}

unsigned long long GetMulti(unsigned int nCnt)
{
    if (0 == nCnt)    return 1;
   
    return nCnt*GetMulti(nCnt - 1);
}

#11
peach54602013-08-15 19:10
回复 10楼 xufan
哎...你们先理解一下题意吧...
题目其实是想考大数运算

你看看39的阶乘...你换long long 也是装不下的,亲...
#12
nanicesky2013-08-16 11:38
这个是acm常考的大数问题,网上关于这方面的算法挺多的,主要就是把数据分块,分成能够表示出来的小数据进行处理,然后再把这些小数据合到最终数据
#13
南方姑娘2013-08-20 10:18
随便看看
#14
镜像2013-08-20 10:28
回复 13楼 南方姑娘
建议你换头像...!
#15
holy__shit2013-08-23 21:25
回复 楼主 linsir
数组模拟!
1