SHARE
TWEET

Untitled

a guest Mar 25th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace _05._Multiply_Big_Number
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             string firstNumber = Console.ReadLine().TrimStart(new char[] { '0' });
  12.             int secondNumber = int.Parse(Console.ReadLine().TrimStart(new char[] { '0' }));
  13.  
  14.             if (secondNumber == 0)
  15.             {
  16.                 Console.WriteLine(0);
  17.                 return;
  18.             }
  19.  
  20.  
  21.             var finalResult = new List<int>();
  22.             int residual = 0;
  23.  
  24.             for (int i = firstNumber.Length - 1; i >= 0; i--)
  25.             {
  26.  
  27.                 int digit = int.Parse(firstNumber[i].ToString());
  28.                 int result = digit * secondNumber + residual;
  29.                 residual = 0;
  30.  
  31.                 if (result <= 9)
  32.                 {
  33.                     finalResult.Add(result);
  34.                 }
  35.                 else
  36.                 {
  37.                     finalResult.Add(result % 10);
  38.                     residual = result / 10;
  39.                 }
  40.             }
  41.             if (residual != 0)
  42.             {
  43.                 finalResult.Add(residual);
  44.             }
  45.  
  46.             finalResult.Reverse();
  47.  
  48.             Console.WriteLine(string.Join("", finalResult));
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top