Exemplo n.º 1
0
 static void Main()
 {
     //Write a method that adds two positive integer numbers represented as arrays of digits (each array element arr[i] contains a digit;
     //the last digit is kept in arr[0]). Each of the numbers that will be added could have up to 10 000 digits.
     char[] numAarr = "321".ToCharArray();
     char[] numBarr = "0168".ToCharArray();
     BigInts instance = new BigInts();
     char[] sum = instance.AddTwoNumbers(numAarr, numBarr);
     string suma = string.Join("", sum);
     Console.WriteLine(sum);
 }
Exemplo n.º 2
0
 public void Task8Test()
 {
     BigInts instance = new BigInts();
     char[] numA = ("4234345345").ToCharArray();
     char[] numB = ("3489734968").ToCharArray();
     string suma = string.Join("", instance.AddTwoNumbers(numA, numB));
     Assert.AreEqual("7724080313",suma);
     numA = ("3").ToCharArray();
     numB = ("11").ToCharArray();
     suma = string.Join("", string.Join("", instance.AddTwoNumbers(numA, numB)));
     Assert.AreEqual("14", suma);
     numA = ("0").ToCharArray();
     numB = ("1").ToCharArray();
     suma = string.Join("", string.Join("", instance.AddTwoNumbers(numA, numB)));
     Assert.AreEqual("1", suma);
     numA = ("99").ToCharArray();
     numB = ("1").ToCharArray();
     suma = string.Join("", string.Join("", instance.AddTwoNumbers(numA, numB)));
     Assert.AreEqual("100", suma);
     numA = ("1").ToCharArray();
     numB = ("99").ToCharArray();
     suma = string.Join("", string.Join("", instance.AddTwoNumbers(numA, numB)));
     Assert.AreEqual("100", suma);
 }
Exemplo n.º 3
0
 static char[] MultTwoNumbers(char[] numA, char[] numB)
 {
     if (numA.Length > numB.Length)
     {
         char[] temp = numA;
         numA = numB;
         numB = temp;
     }
     List<char[]> addends = new List<char[]>();
     int lengthA = numA.Length;
     int zeros = 0;
     char[] addend = new char[0];
     char[] totalSum = new char[0];
     BigInts instance = new BigInts();
     Array.Reverse(numA);
     Array.Reverse(numB);
     for (int i = 0; i < lengthA; i++)
     {
         addend = CreateAddend(numA[i],numB,zeros);
         zeros++;
         addends.Add(addend);
     }
     for (int i = 0; i < addends.Count; i++)
     {
         Array.Reverse(addends[i]);
         totalSum = instance.AddTwoNumbers(totalSum, addends[i]);
     }
     return totalSum;
 }