大数据的乘法应用——阶乘(初学者的情怀)
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 對于我這個初學者來說,對于大數據的處理還是蠻頭大的,而此文主要給出了階乘下的大數據的乘法,分享給大家。。。。。
?
#include<iostream> #include<iomanip> #define MAX 201 #define BASE 10000 //數字中每個元素保存4位(即基) using namespace std; int f[MAX][MAX]; //第一個維度保存序號,第二個維度該序號下的階乘值 void multiply(int a[], int b) //大數乘法處理,單語句操作,意會其過程 {int carry = 0;for (int len = MAX - 1; len >= 0; len--){carry += a[len] * b;a[len] = carry%BASE;carry /= BASE;} } int factorial(int n,int i) //階乘 {memset(f, 0, sizeof(int)*MAX*MAX);f[i][MAX - 1] = n;for (int j = n-1; j > 0; j--){multiply(f[i], j);}return 0; }int main() {int m, i,j;while (cin >> j>>m){factorial(m, j);for (i = 0; i < MAX; i++) //找到第一個非零的開始打印{if (f[j][i]!= 0)break;}if (i < MAX) //打印的方法,應當注意中間位數不足4位時{cout << f[j][i++];for (; i < MAX; i++){if (f[j][i] < 10000)cout << setw(4) << setfill('0') << f[j][i];elsecout << f[j][i];}cout << endl;}}return 0; } </iomanip></iostream>
總結
以上是生活随笔為你收集整理的大数据的乘法应用——阶乘(初学者的情怀)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用freemarker模板生成带图片的
- 下一篇: 你真的知道什么叫创业吗?