Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- namespace _08.AddTwoIntegersVersion2
- {
- class Program
- {
- static void CreatingArray(int[] arrayNum)
- {
- Random numbers = new Random();
- for (int i = 0; i<arrayNum.Length; i++)
- {
- arrayNum[i] = numbers.Next(0,9);
- }
- }
- static void PrintArray(int[] array)
- {
- for (int i = array.Length -1; i >=0 ; i--)
- {
- Console.Write(array[i]);
- }
- }
- static BigInteger ConvertingArrayTo(int[] arrayNum)
- {
- BigInteger powerOf10 = 1;
- BigInteger resultNum = 0;
- for (int i = 0; i < arrayNum.Length; i++)
- {
- resultNum += arrayNum[i] * powerOf10;
- powerOf10 *= 10;
- }
- return resultNum;
- }
- static BigInteger CalcSum(BigInteger firstNum, BigInteger secondSum)
- {
- return firstNum + secondSum;
- }
- static void Main(string[] args)
- {
- Console.Write("How many digits will be the first number? ");
- int digitsFirstNum = int.Parse(Console.ReadLine());
- Console.Write("How many digits will be the second number? ");
- int digitsSecondNum = int.Parse(Console.ReadLine());
- int[] firstArray = new int[digitsFirstNum];
- int[] secondArray = new int[digitsSecondNum];
- CreatingArray(firstArray);
- CreatingArray(secondArray);
- Console.WriteLine("FistArray:");
- PrintArray(firstArray);
- Console.WriteLine();
- Console.WriteLine("SecondArray:");
- PrintArray(secondArray);
- Console.WriteLine();
- Console.WriteLine("FirstNumber:");
- Console.WriteLine(ConvertingArrayTo(firstArray));
- Console.WriteLine("SecondNumber:");
- Console.WriteLine(ConvertingArrayTo(secondArray));
- Console.WriteLine("Their sum:");
- Console.WriteLine(CalcSum(ConvertingArrayTo(firstArray), ConvertingArrayTo(secondArray)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement