本文主要是介绍高精度加法,乘法,阶乘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
const int Max = 50000;
string str1,str2;/***********乘法***********/
void chenfa()
{cin >> str1>>str2;int a[20000] = {0},b[20000] = {0},c[50000] = {0};int len1 = str1.length();int len2 = str2.length();for(int i = 0 ; i< len1; i++){a[i] = str1[len1-1-i]-'0';//字符串转化为整型}for(int i = 0 ; i< len2; i++){b[i] = str2[len2-1-i]-'0';}for(int i = 0 ; i < len1; i++ ){for(int j = 0 ; j < len2 ; j++){c[i + j] += a[i] * b [j];//核心代码c[i + j + 1] += c[i + j]/10;//核心代码c[i + j] %= 10;//核心代码}}int len = len1 + len2;while(!c[len]) len--;for(int i = len; i>=0 ; i--){cout<<c[i];}cout<<endl;
}/***********加法***********/
void jiafa()
{cin >> str1>>str2;int a[2000],b[2000];int len1 = str1.length();int len2 = str2.length();for(int i = 0 ; i< len1; i++){a[i] = str1[len1-1-i]-'0';}for(int i = 0 ; i< len2; i++){b[i] = str2[len2-1-i]-'0';}int len = max(len1,len2);for(int i = 0; i < len ; i++){a[i] += b[i];a[i+1] += a[i]/10;a[i] %= 10;}len++;while(!a[len])len--;for(int i = len; i >=0 ; i--)cout<<a[i];cout<<endl;}/********N!*************/
void jiechen()
{int a[Max];int Count ,N;;a[0] = 1;cin>>N;Count = 1;for(int i = 2; i <= N; i++){int k = 0;for(int j = 0; j < Count; j++){int temp = a[j]*i + k;a[j] = temp%10;k = temp/10;}while(k){a[Count++] = k%10;k /= 10;}}for(int i = Max-1; i >= 0 ; i--){if(a[i]) break;//除去前导0}for(int i = Count - 1; i >= 0; i--){cout<<a[i];}
}
这篇关于高精度加法,乘法,阶乘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!