C # Big Data calculator-Multiplication

Source: Internet
Author: User

Class bigmultiply: bigcalculate
 

{

Public override string evaluate (string num1, string num2)

{

If (num1.equals ("0") | num2.equals ("0 "))

{

Return "0 ";

}


List liallnum = new list (); // stores the result of each multiplication of the multiplier.

List Lich = new list (); // stores the result of each digit of the multiplier multiplication.


// Assign a long number to num1 for later Computation

If (num1.length <num2.length)

{

Changenum (ref num1, ref num2 );

}


Int flag;

For (INT I = num2.length-1; I> = 0; I --)

{

// Initialize the data in the previous multiplication.

Lich. Clear ();

Flag = 0;

// Calculate the I-th digit multiplied by the J-th Digit

For (Int J = num1.length-1; j> = 0; j --)

{

Lich. Add (char) (num2 [I]-'0') * (num1 [J]-'0') + flag + '0 '));

Flag = (Lich [lich. Count-1]-'0')/10;

Lich [lich. Count-1] = (char) (Lich [lich. Count-1]-'0') %
10 + '0 ');

}

// If the carry value is not 0, add a bit

If (flag> 0)

{

Lich. Add (char) (flag + '0 '));

}

// Add a result set

Liallnum. Add (invertorder (new string (lich. toarray () + new
String ('0', liallnum. Count ));

}

Int COUNT = 0;

String res = "0 ";

// Call the add method to add the result of each multiplication, that is, the result

Bigadd addoper = new bigadd ();

While (count

{

Res = addoper. Loads (Res, liallnum [count]);

Count ++;

}


Return res;

}
}

Related Article

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.