c++初级编程 求大神指点
长整数四则运算【问题描述】设计任意两个长正整数(小于80位)的加法函数add()和乘法函数mult(),并求任意整数(≤58)的阶乘。
【实现提示】用无符号整型或字符型数组存储任意长整数。
【测试数据】
6!=720
9!=362880
19!=1216451004088320000
39!=20397882081197443358640281739902897356800000000
#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); }
#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); }