Advertisement
rori4

MultiplyBigNumbersProgram

Oct 20th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MultiplyBigNumbers
  8. {
  9.     class MultiplyBigNumbersProgram
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string firstNumber = Console.ReadLine().TrimStart(new char[] { '0' });
  14.             string secondNumber = Console.ReadLine().TrimStart(new char[] { '0' });
  15.  
  16.             byte sum = 0;
  17.             byte numberInMind = 0;
  18.             byte remainder = 0;
  19.             StringBuilder result = new StringBuilder();
  20.  
  21.             for (int i = firstNumber.Length - 1; i >= 0; i--)
  22.             {
  23.                 for (int j = secondNumber.Length - 1; j >=0; j--)
  24.                 {
  25.                     sum = (byte)(byte.Parse(firstNumber[i].ToString()) * byte.Parse(secondNumber[j].ToString()) + numberInMind);
  26.                     numberInMind = (byte)(sum / 10);
  27.                     remainder = (byte)(sum % 10);
  28.                     result.Append(remainder);
  29.                     if (i == 0 && numberInMind != 0)
  30.                     {
  31.                         result.Append(numberInMind);
  32.                     }
  33.                 }
  34.                
  35.             }
  36.  
  37.             char[] resultToChar = result.ToString().ToCharArray();
  38.             Array.Reverse(resultToChar);
  39.             Console.WriteLine(new string(resultToChar));
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement