61-题目1076:N的阶乘
来源:互联网 发布:淘宝活动倒计时代码 编辑:程序博客网 时间:2024/05/19 00:50
http://ac.jobdu.com/problem.php?pid=1076
- 题目描述:
输入一个正整数N,输出N的阶乘。
- 输入:
正整数N(0<=N<=1000)
挺好一题目,因为是大数据,所以用代码模拟了大脑计算乘法的步骤,非常精巧
// 输入一个正整数N,输出N的阶乘//1000的阶乘有2600位左右#include<iostream>#include<fstream>#include<string>using namespace std;int main(){int N, res[10000] = {0}; //正整数N(0<=N<=1000)ifstream cin("data.txt");while (cin >> N){int i, j;memset(res, 0, sizeof(res)); //内存空间初始化 res[0] = 1, res[1] = 1; //res[0]表示结果此时有多少位,初始为1位,res[1]为1表示阶乘的1*.....for (i = 2; i <= N; i++){for (j = 1; j <= res[0]; j++){res[j] = res[j] * i;}for (j = 1; j <= res[0]; j++){if (res[j] >= 10){res[j + 1] += res[j] / 10;res[j] = res[j] % 10;if (j == res[0])//有进位,改变位数res[0]++;}}}for (j = res[0]; j >= 1; j--)cout << res[j];cout << endl;}//end of whilesystem("pause");return 0;}
0 0
- 61-题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目1076:N的阶乘
- 题目61:N的阶乘
- 题目61:N的阶乘
- 九度题目1076:N的阶乘
- 题目1067:n的阶乘
- 题目1067:n的阶乘
- 题目1067:n的阶乘
- 九度oj 题目1076:N的阶乘
- 九度OJ 题目1076:N的阶乘
- 九度 oj 题目1076:N的阶乘
- Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务
- HDU 1.3.1 FatMouse' Trade
- Android之来电秀实现(一)
- Rust hello world 语法讲解
- HDU 1.3.2 Tian Ji -- The Horse Racing
- 61-题目1076:N的阶乘
- 实用ListView加载提示工具类
- HDU 1.3.3 开门人和关门人
- iOS电池条颜色修改
- 自定义ImageLoader实现GridView加载图片
- 第2周项目3—小试循环(4)
- HDU 1.3.4 What Is Your Grade?
- nginx http 与https 共存,并设置参数
- appium上调试ios真机的各种问题