Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq.Expressions;
- namespace Infint
- {
- class Infint
- {
- static string num1;
- static string num2;
- static char[] charArr1;
- static char[] charArr2;
- static int[] intArr1;
- static int[] intArr1Corrected;
- static int[] intArr2;
- static int[] intArr2Corrected;
- static int[] sumArr;
- static void Main()
- {
- Start();
- }
- static void Start()
- {
- introduction();
- getNum();
- toCharArr(num1,num2);
- printPowTen(charArr1);
- printPowTen(charArr2);
- fillInt1();
- fillInt2();
- sum(intArr1, intArr2);
- printSum();
- }
- #region functions
- //introduction of the program
- static void introduction()
- {
- Console.WriteLine("Hello. This is an INFINIT program.");
- Console.WriteLine("You will have to enter 2 numbers, that are larger than int or long datatype. ");
- Console.WriteLine("Int (- 2 147 483 648 : 2 147 483 647)");
- Console.WriteLine("Long (-9 223 372 036 854 775 808 : 9 223 372 036 854 775 807)");
- Console.WriteLine();
- }
- //end of the introduction function
- //function to get 2 numbers
- static void getNum()
- {
- Console.Write("Enter the first number: ");
- num1 = Console.ReadLine();
- Console.WriteLine();
- Console.Write("Enter the second number: ");
- num2 = Console.ReadLine();
- }
- //end of getNum func
- //function to convert num1 and num2 to char arrays
- static void toCharArr(string num1, string num2)
- {
- charArr1=num1.ToCharArray();
- charArr2=num2.ToCharArray();
- }
- //end of toCharArr func
- //function to turn char arr elements into ints and fill an int arr with these elements
- #region fill functions
- static void fillInt1()
- {
- intArr1 = new int[charArr1.Length];
- for (int i = 0; i < charArr1.Length; i++)
- {
- intArr1[i] = Convert.ToInt32(charArr1[i].ToString());
- }
- }
- static void fillInt2()
- {
- intArr2 = new int[charArr2.Length];
- for (int i = 0; i < charArr2.Length; i++)
- {
- intArr2[i] = Convert.ToInt32(charArr2[i].ToString());
- }
- }
- #endregion
- //end of fillInt func
- //function to print numbers with pows of 10
- #region print functions
- //function to print these numbers with the powers of 10
- static void printPowTen(char[] Arr)
- {
- int index = Arr.Length - 1;
- Console.Write("Number represented in powers of ten: ");
- for (int i = 0; i < Arr.Length; i++)
- {
- if (i + 1 == Arr.Length) { Console.Write($"{Arr[i]} * 10 ^ {index--}"); }
- else if (Arr.Length > i + 1) { Console.Write($"{Arr[i]} * 10 ^ {index--} + "); }
- }
- Console.WriteLine();
- Console.WriteLine();
- }
- #endregion
- //end of printPowTen func
- //function for summition of two numbers
- static void sum(int[] arr1, int[]arr2)
- {
- if (arr1.Length == arr2.Length || arr1.Length > arr2.Length) { sumArr = new int[arr1.Length]; }
- else if (arr1.Length < arr2.Length) { sumArr = new int[arr2.Length]; }
- for (int i = 0; i < sumArr.Length; i++)
- {
- if (arr1.Length == arr2.Length)
- {
- if (i < arr1.Length && i < arr2.Length) { sumArr[i] = arr1[i] + arr2[i]; }
- else if (i >= arr1.Length || i >= arr2.Length) { sumArr[i] = 0; }
- else if (i >= arr1.Length && i < arr2.Length) { sumArr[i] = arr2[i]; }
- else if (i < arr1.Length && i >= arr2.Length) { sumArr[i] = arr1[i]; }
- }
- else if (arr1.Length > arr2.Length)
- {
- int difference=arr1.Length - arr2.Length;
- intArr2Corrected = new int[arr2.Length + difference];
- for (int f = 0; f < difference; f++) { intArr2Corrected[f + difference] = arr1[f]; }
- for (int j = 0; j < difference; j++)
- {
- arr2[j] = 0;
- }
- if (i < arr1.Length && i < arr2.Length) { sumArr[i] = arr1[i] + arr2[i]; }
- else if (i >= arr1.Length || i >= intArr2Corrected.Length) { sumArr[i] = 0; }
- else if (i >= arr1.Length && i < intArr2Corrected.Length) { sumArr[i] = arr2[i]; }
- else if (i < arr1.Length && i >= intArr2Corrected.Length) { sumArr[i] = arr1[i]; }
- }
- else if (arr1.Length < arr2.Length)
- {
- int difference = arr2.Length - arr1.Length;
- intArr1Corrected = new int[arr1.Length + difference];
- for(int f = 0; f < difference; f++) { intArr1Corrected[f+difference] = arr1[f]; }
- for (int j = 0; j < difference; j++)
- {
- intArr1Corrected[j] = 0;
- }
- if (i < intArr1Corrected.Length && i < arr2.Length) { sumArr[i] = intArr1Corrected[i] + arr2[i]; }
- else if (i >= intArr1Corrected.Length || i >= arr2.Length) { sumArr[i] = 0; }
- else if (i >= intArr1Corrected.Length && i < arr2.Length) { sumArr[i] = arr2[i]; }
- else if (i < intArr1Corrected.Length && i >= arr2.Length) { sumArr[i] = arr1[i]; }
- }
- }
- }
- //end of func
- //function to print the sum amount
- static void printSum()
- {
- Console.Write("Sum: ");
- int index = sumArr.Length - 1;
- for(int i = 0; i < sumArr.Length; i++)
- {
- if (sumArr.Length > i + 1)
- {
- Console.Write($"{sumArr[i]} * 10 ^ {index--} + ");
- }
- else
- {
- Console.Write($"{sumArr[i]} * 10 ^ {index--} ");
- }
- }
- }
- //end of func
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment