Advertisement
geniusvil

Methods - 08

Dec 14th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace _08.AddTwoIntegersVersion2
  9. {
  10. class Program
  11. {
  12. static void CreatingArray(int[] arrayNum)
  13. {
  14. Random numbers = new Random();
  15. for (int i = 0; i<arrayNum.Length; i++)
  16. {
  17. arrayNum[i] = numbers.Next(0,9);
  18. }
  19. }
  20. static void PrintArray(int[] array)
  21. {
  22. for (int i = array.Length -1; i >=0 ; i--)
  23. {
  24. Console.Write(array[i]);
  25. }
  26. }
  27. static BigInteger ConvertingArrayTo(int[] arrayNum)
  28. {
  29. BigInteger powerOf10 = 1;
  30. BigInteger resultNum = 0;
  31. for (int i = 0; i < arrayNum.Length; i++)
  32. {
  33. resultNum += arrayNum[i] * powerOf10;
  34. powerOf10 *= 10;
  35. }
  36. return resultNum;
  37. }
  38.  
  39. static BigInteger CalcSum(BigInteger firstNum, BigInteger secondSum)
  40. {
  41. return firstNum + secondSum;
  42. }
  43. static void Main(string[] args)
  44. {
  45. Console.Write("How many digits will be the first number? ");
  46. int digitsFirstNum = int.Parse(Console.ReadLine());
  47. Console.Write("How many digits will be the second number? ");
  48. int digitsSecondNum = int.Parse(Console.ReadLine());
  49.  
  50. int[] firstArray = new int[digitsFirstNum];
  51. int[] secondArray = new int[digitsSecondNum];
  52.  
  53. CreatingArray(firstArray);
  54. CreatingArray(secondArray);
  55.  
  56. Console.WriteLine("FistArray:");
  57. PrintArray(firstArray);
  58. Console.WriteLine();
  59.  
  60. Console.WriteLine("SecondArray:");
  61. PrintArray(secondArray);
  62. Console.WriteLine();
  63.  
  64. Console.WriteLine("FirstNumber:");
  65. Console.WriteLine(ConvertingArrayTo(firstArray));
  66. Console.WriteLine("SecondNumber:");
  67. Console.WriteLine(ConvertingArrayTo(secondArray));
  68. Console.WriteLine("Their sum:");
  69. Console.WriteLine(CalcSum(ConvertingArrayTo(firstArray), ConvertingArrayTo(secondArray)));
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement