Advertisement
Assi

SumDigitsOfTwoArrays

Jan 13th, 2013
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Text;
  4.  
  5.  
  6. static class SumDigitsOfArray
  7. {
  8.     static string ToStringNonLinqy<T>(this T[] array, string delimiter)
  9.     {
  10.         if (array != null)
  11.         {
  12.             if (array.Length > 0)    
  13.             {
  14.                 StringBuilder builder = new StringBuilder();
  15.  
  16.                 builder.Append(array[0]);
  17.                 for (int i = 1; i < array.Length; i++)
  18.                 {
  19.                     builder.Append(delimiter);
  20.                     builder.Append(array[i]);
  21.                 }
  22.                 return builder.ToString();
  23.             }
  24.             else
  25.             {
  26.                 return string.Empty;
  27.             }
  28.         }
  29.         else
  30.         {
  31.             return null;
  32.         }
  33.     }
  34.     static BigInteger Sum(BigInteger n1, BigInteger n2)
  35.     {
  36.         return n1 + n2;
  37.     }
  38.  
  39.     static void Main()
  40.     {
  41.         byte[] arr1 = { 4,4,2,3,2 };
  42.         Array.Reverse(arr1);
  43.         byte[] arr2 = { 2,2,2,2,2,4,4,4,4 };
  44.         Array.Reverse(arr2);
  45.  
  46.         BigInteger arr1Digits = BigInteger.Parse(ToStringNonLinqy(arr1, string.Empty));
  47.         BigInteger arr2Digits = BigInteger.Parse(ToStringNonLinqy(arr2, string.Empty));
  48.  
  49.         Console.WriteLine(Sum(arr1Digits,arr2Digits));
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement