C + + implements large number multiplication

Source: Internet
Author: User

#include <string.h> #include <iostream> #import <foundation/foundation.h>using namespace std;# Define INT (x) (X-' 0 ') #define CHAR (x) (x + ' 0 ') char a[100]={0};char b[100]={0};//quadrature char *multibiginteger (char *, char *) ;//Check whether the digits of each number meet the requirements bool Checknum (char *);//print void num (char*,int) for the desired product,//for length int len (char*), int main () {while (scanf ("%s% S ", A, B)) {if (Checknum (a) | | Checknum (b)) {continue;} else{char * arr = Multibiginteger (A, b); Num (arr, Len (arr));} cout<<a<<endl<<b<<endl; } return 0;} BOOL Checknum (char *ch) {bool Bo = NO; char * temp = ch; int lan = 0; while (Lan<strlen (temp)) {//) as long as there is a range that does not return within 0 to 9 Flase if (temp[lan]< ' 0 ' | | temp[lan]> ' 9 ') {bo = YES; cout<< "<<temp[lan]<<" you entered does not meet the requirements, can only enter 1 to 9 any one!!! "<<endl; Break } ++temp; ++lan; } return Bo; void num (char* a,int len) {int temp = len; cout<< "product is:";//temp-=1; for (; temp>=0;temp--) {if (!) ( (Temp==len) && (a[temp]== ' 0 ')) {cout<<a[temp];} Cout<<a[temp]; } Cout<<endl;} Ask for an array of length int len (char* a) {int len=0; while (*a) {++a; ++len;} return len;} Char *multibiginteger (char *a, char *b) {int lengtha = Len (a),//a length int lengthb = len (b);//b length char* Arrayab = Nullpt R Application for a memory storage product//arrayab= (char*) malloc ((lengthb+lengtha-1) *sizeof (char)); arrayab= New Char[lengthb+lengtha]; memset (Arrayab, ' 0 ', (lengthb+lengtha) *sizeof (char)); cout<<arrayab[0]<<endl; int ji = 0; int Jigewei = 0; int Jijinwei = 0; int he = 0; int Hegeiwei = 0; int Hejinwei = 0; int Painyi = 0; int temp = 0; for (int i = lengthb-1; i>=0; i--) {//b Painyi = temp, for (int j = lengtha-1; j>=0; j--) {//a char ChB = b[i]; char Cha = a[j];//cout<<cha<<chb<<endl;//cout<< a[i]<<b[j]<<endl; Ji = Int (ChB) *int (cha) +jijinwei; Jigewei =ji%10; Jijinwei = ji/10;//cout<< "Lengtha" <<lengtha<< "LENGTHB" <<lengthb<< "Ji" <<ji <<int (CHA) <<int (CHB) <<endl; he = JigeWei+hejinwei+int (Arrayab[painyi]); Hegeiwei= he%10; Hejinwei= HE/10; Arrayab[painyi]=char (Hegeiwei); Arrayab[painyi+1]=char (Jijinwei); ++painyi; } ++temp; } return Arrayab;}

Reference Blog Address:
https://www.cnblogs.com/king-ding/p/bigIntegerMul.html please add a link description

C + + implements large number multiplication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.