Advertisement
Martichka

[C#] Methods/ Task - 08 Big Number in Array

Jan 23rd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. class BigNumsInArray
  4. {
  5.     static int[] ReverseArray(int[] arr)
  6.     {
  7.         int[] reversed = new int[arr.Length];
  8.         Array.Reverse(arr);
  9.         for (int i = 0; i < arr.Length; i++)
  10.             {
  11.                 reversed[i]=arr[i];
  12.             }
  13.         return reversed;
  14.     }
  15.     static BigInteger SumArrays(int[] arr1, int[] arr2)
  16.     {
  17.         BigInteger sum = 0;
  18.         string num1="";
  19.         string num2 = "";
  20.         for (int i = 0; i < arr1.Length; i++)
  21.         {
  22.             num1 += arr1[i].ToString();
  23.         }
  24.         for (int i = 0; i < arr2.Length; i++)
  25.         {
  26.             num2 += arr2[i].ToString();
  27.         }
  28.         BigInteger first = BigInteger.Parse(num1);
  29.         BigInteger second = BigInteger.Parse(num2);
  30.         sum = first + second;
  31.         return sum;
  32.     }
  33.     static void Main()
  34.     {
  35.         int[] firsArr = { 1, 6, 5, 9, 1, 5, 3, 2, 7 };
  36.         int[] secondArr = { 4, 5, 7, 9, 4, 7, 1, 6, 2 };
  37.         int[] reversedFirst = ReverseArray(firsArr);
  38.         int[] reversedSecond = ReverseArray(secondArr);
  39.         BigInteger sum = SumArrays(reversedFirst, reversedSecond);
  40.         Console.WriteLine(sum);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement