erehh

infinit mxolod jamit

Oct 30th, 2022
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.57 KB | None | 0 0
  1. using System.Linq.Expressions;
  2.  
  3. namespace Infint
  4. {
  5.     class Infint
  6.     {
  7.  
  8.         static string num1;
  9.         static string num2;
  10.  
  11.         static char[] charArr1;
  12.         static char[] charArr2;
  13.  
  14.         static int[] intArr1;
  15.         static int[] intArr1Corrected;
  16.         static int[] intArr2;
  17.         static int[] intArr2Corrected;
  18.         static int[] sumArr;
  19.  
  20.         static void Main()
  21.         {
  22.             Start();
  23.         }
  24.  
  25.         static void Start()
  26.         {
  27.             introduction();
  28.  
  29.             getNum();
  30.  
  31.             toCharArr(num1,num2);
  32.  
  33.             printPowTen(charArr1);
  34.             printPowTen(charArr2);
  35.  
  36.             fillInt1();
  37.             fillInt2();
  38.  
  39.             sum(intArr1, intArr2);
  40.  
  41.             printSum();
  42.            
  43.         }
  44.  
  45.         #region functions
  46.         //introduction of the program
  47.         static void introduction()
  48.         {
  49.             Console.WriteLine("Hello. This is an INFINIT program.");
  50.             Console.WriteLine("You will have to enter 2 numbers, that are larger than int or long datatype. ");
  51.             Console.WriteLine("Int (- 2 147 483 648 : 2 147 483 647)");
  52.             Console.WriteLine("Long (-9 223 372 036 854 775 808 : 9 223 372 036 854 775 807)");
  53.             Console.WriteLine();
  54.         }
  55.         //end of the introduction function
  56.  
  57.         //function to get 2 numbers
  58.         static void getNum()
  59.         {
  60.             Console.Write("Enter the first number: ");
  61.             num1 = Console.ReadLine();
  62.  
  63.             Console.WriteLine();
  64.  
  65.             Console.Write("Enter the second number: ");
  66.             num2 = Console.ReadLine();
  67.  
  68.         }
  69.         //end of getNum func
  70.  
  71.         //function to convert num1 and num2 to char arrays
  72.         static void toCharArr(string num1, string num2)
  73.         {
  74.             charArr1=num1.ToCharArray();
  75.             charArr2=num2.ToCharArray();
  76.         }
  77.         //end of toCharArr func
  78.  
  79.         //function to turn char arr elements into ints and fill an int arr with these elements
  80.         #region fill functions
  81.         static void fillInt1()
  82.         {
  83.             intArr1 = new int[charArr1.Length];
  84.  
  85.             for (int i = 0; i < charArr1.Length; i++)
  86.             {
  87.                 intArr1[i] = Convert.ToInt32(charArr1[i].ToString());
  88.             }
  89.         }
  90.  
  91.         static void fillInt2()
  92.         {
  93.             intArr2 = new int[charArr2.Length];
  94.  
  95.             for (int i = 0; i < charArr2.Length; i++)
  96.             {
  97.                 intArr2[i] = Convert.ToInt32(charArr2[i].ToString());
  98.             }
  99.         }
  100.         #endregion
  101.         //end of fillInt func
  102.  
  103.         //function to print numbers with pows of 10
  104.         #region print functions
  105.         //function to print these numbers with the powers of 10
  106.         static void printPowTen(char[] Arr)
  107.         {
  108.             int index = Arr.Length - 1;
  109.  
  110.             Console.Write("Number represented in powers of ten: ");
  111.             for (int i = 0; i < Arr.Length; i++)
  112.             {
  113.                 if (i + 1 == Arr.Length) { Console.Write($"{Arr[i]} * 10 ^ {index--}"); }
  114.                 else if (Arr.Length > i + 1) { Console.Write($"{Arr[i]} * 10 ^ {index--} + "); }
  115.             }
  116.             Console.WriteLine();
  117.             Console.WriteLine();
  118.         }
  119.         #endregion
  120.         //end of printPowTen func
  121.  
  122.         //function for summition of two numbers
  123.         static void sum(int[] arr1, int[]arr2)
  124.         {
  125.             if (arr1.Length == arr2.Length || arr1.Length > arr2.Length) { sumArr = new int[arr1.Length]; }
  126.             else if (arr1.Length < arr2.Length) { sumArr = new int[arr2.Length]; }
  127.  
  128.             for (int i = 0; i < sumArr.Length; i++)
  129.             {
  130.                 if (arr1.Length == arr2.Length)
  131.                 {
  132.                     if (i < arr1.Length && i < arr2.Length) { sumArr[i] = arr1[i] + arr2[i]; }
  133.                     else if (i >= arr1.Length || i >= arr2.Length) { sumArr[i] = 0; }
  134.                     else if (i >= arr1.Length && i < arr2.Length) { sumArr[i] = arr2[i]; }
  135.                     else if (i < arr1.Length && i >= arr2.Length) { sumArr[i] = arr1[i]; }
  136.                 }
  137.                 else if (arr1.Length > arr2.Length)
  138.                 {
  139.                     int difference=arr1.Length - arr2.Length;
  140.                     intArr2Corrected = new int[arr2.Length + difference];
  141.                     for (int f = 0; f < difference; f++) { intArr2Corrected[f + difference] = arr1[f]; }
  142.                     for (int j = 0; j < difference; j++)
  143.                     {
  144.                         arr2[j] = 0;
  145.                     }
  146.  
  147.                     if (i < arr1.Length && i < arr2.Length) { sumArr[i] = arr1[i] + arr2[i]; }
  148.                     else if (i >= arr1.Length || i >= intArr2Corrected.Length) { sumArr[i] = 0; }
  149.                     else if (i >= arr1.Length && i < intArr2Corrected.Length) { sumArr[i] = arr2[i]; }
  150.                     else if (i < arr1.Length && i >= intArr2Corrected.Length) { sumArr[i] = arr1[i]; }
  151.  
  152.  
  153.                 }
  154.                 else if (arr1.Length < arr2.Length)
  155.                 {
  156.                     int difference = arr2.Length - arr1.Length;
  157.                     intArr1Corrected = new int[arr1.Length + difference];
  158.                     for(int f = 0; f < difference; f++) { intArr1Corrected[f+difference] = arr1[f]; }
  159.                    
  160.                     for (int j = 0; j < difference; j++)
  161.                     {
  162.                         intArr1Corrected[j] = 0;
  163.                     }
  164.  
  165.                     if (i < intArr1Corrected.Length && i < arr2.Length) { sumArr[i] = intArr1Corrected[i] + arr2[i]; }
  166.                     else if (i >= intArr1Corrected.Length || i >= arr2.Length) { sumArr[i] = 0; }
  167.                     else if (i >= intArr1Corrected.Length && i < arr2.Length) { sumArr[i] = arr2[i]; }
  168.                     else if (i < intArr1Corrected.Length && i >= arr2.Length) { sumArr[i] = arr1[i]; }
  169.                 }
  170.                
  171.             }
  172.         }
  173.         //end of func
  174.  
  175.         //function to print the sum amount
  176.         static void printSum()
  177.         {
  178.             Console.Write("Sum: ");
  179.             int index = sumArr.Length - 1;
  180.  
  181.             for(int i = 0; i < sumArr.Length; i++)
  182.             {
  183.                 if (sumArr.Length > i + 1)
  184.                 {
  185.                     Console.Write($"{sumArr[i]} * 10 ^ {index--} + ");
  186.                 }
  187.                 else
  188.                 {
  189.                     Console.Write($"{sumArr[i]} * 10 ^ {index--} ");
  190.                 }
  191.             }
  192.         }
  193.         //end of func
  194.         #endregion
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment