欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

C++實(shí)現(xiàn)大數(shù)乘法算法代碼

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

C++實(shí)現(xiàn)大數(shù)乘法算法代碼

復(fù)制代碼 代碼如下:

//大數(shù)乘法算法
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    string num1,num2;
    cin >> num1 >> num2;
    //cout << num1.size() << " " << num2.size() << endl;
    const char* n1;
    const char* n2;
    if (num1.size() < num2.size())
    {
        n1 = num2.c_str();
        n2 = num1.c_str();
    }
    else
    {
        n1 = num1.c_str();
        n2 = num2.c_str();
    }
    char* n = new char[strlen(n1)+strlen(n2)+1];
    for (unsigned int i = 0; i < strlen(n1)+strlen(n2); i++)
        n[i] = '0';
    n[strlen(n1)+strlen(n2)]='\0';
    //cout << strlen(n) << endl;
    int count = 0,flag = 0;
    for (int i = strlen(n1)-1; i >= 0; i--)
    {
        flag++;
        int x1 = n1[i]-'0';
        //cout << "n1["<< i << "]為:" << x1 << endl;
        char carry = '0';
        for (int j = strlen(n2)-1; j >= 0; j--)
        {
            int x2 = n2[j]-'0';
            //cout << "n2["<< j << "]為:" << x2 << endl;
            //cout << "當(dāng)前位未改變前值為: " << n[count] << endl;
            int sum = x1*x2 + (carry-'0') + n[count]-'0';
            //cout << "sum is " << sum << endl;
            n[count++] = (sum % 10)+'0';
            carry = (sum / 10)+'0';
            //cout << "當(dāng)前位的值為: " << n[count-1] << endl;
            //cout << "carry的值為:" << carry << endl;
        }
        if (carry != '0')
        {
            n[count] = carry;
            count = flag;
            //cout << "當(dāng)前位的值為: " << n[count] << endl;
        }
        else
            count = flag;
    }
    for (int i = strlen(n)-1; i >= 0; i--)
    {
        if ((i == strlen(n)-1)&&(n[i] == '0'))
            continue;
        cout << n[i];
    }
    cout << endl;
    delete[]n;
    system("pause");
    return 0;
}

以上就是本文所述的全部?jī)?nèi)容了,希望大家能夠喜歡。

上一篇:C語(yǔ)言中的強(qiáng)符號(hào)和弱符號(hào)介紹

欄    目:C語(yǔ)言

下一篇:用VC++6.0實(shí)現(xiàn)石頭剪刀布游戲的程序

本文標(biāo)題:C++實(shí)現(xiàn)大數(shù)乘法算法代碼

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3150.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有