i need help with this program
subtracting 2 large numbers using string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SUBTRACTION PROGRAM
{
class Arithmetic
{
static void Main(string[] args)
{
const int LENGTH = 1000;
String In1;
String In2;
String Out;
int[] Top = new int[LENGTH];
int[] Bottom = new int[LENGTH];
int[] Dif = new int[LENGTH - 1];
StringBuilder temp;
int borrow = 0;
int TopLen = 0;
int BottomLen = 0;
int LenDif = 0;
int SumLen = 0;
int TopIn = 0;
int BottomIn = 0;
Console.WriteLine("Doing Subtraction\n");
Console.Write("Enter the First Number: ");
In1 = Console.ReadLine();
Console.Write("Enter the Second Number: ");
In2 = Console.ReadLine();
//GETTING LARGER NUMBER ON TOP
// if(In1 < In2) //first shorter than second
{
for (int i = 0; i < TopLen; i++)
{
if (In1[i] < In2[i]) ;
Top[i] = In2[i] - '0';
}
LenDif = TopLen - BottomLen;
for (int i = 0; i < LenDif; i++)
{
Bottom[i] = 0; // pad bottom with zeros on left
}
for (int i = 0; i < BottomLen; i++)
{
Bottom[i + LenDif] = In1[i] - '0';
}
}
else
// if (In2 < In1 )
{
TopLen = In1.Length;
BottomLen = In2.Length;
for (int i = 0; i < TopLen; i++)
{
Top[i] = In1[i] - '0';
}
LenDif = TopLen - BottomLen;
for (int i = 0; i < LenDif; i++)
{
Bottom[i] = 0;
}
for (int i = 0; i < BottomLen; i++)
{
Bottom[i + LenDif] = In2[i] - '0';
}
}
// start subtraction from the left and work back to right
//---------------DOING ARITHMETIC---------------------------
for (int i = TopLen -1; i >= 0; i--)
{
//two inputs are same
if (In1[i] == In2[i])
{
Out = 0; // figure out.....
}
//one of the numbers is zero
else
{
if (BottomIn == 0)
{
Out = Top[i];
}
}
else
{
if (TopIn == 0)
{
Bottom[i] = Out;
}
}
}
for (int i = TopLen -1 -BottomLen)
{
//two digits plus borrow
if(i > TopLen -1 -BottomLen)
{
Dif[i] = Top[i] - Bottom[i];
if (Top[i] == 0)
{
borrow = 1;
Top[i] = 10;
Top[i] -= 9;
}
else
{
borrow = 0;
}
}
What I have tried:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SUBTRACTION PROGRAM
{
class Arithmetic
{
static void Main(string[] args)
{
const int LENGTH = 1000;
String In1;
String In2;
String Out;
int[] Top = new int[LENGTH];
int[] Bottom = new int[LENGTH];
int[] Dif = new int[LENGTH - 1];
StringBuilder temp;
int borrow = 0;
int TopLen = 0;
int BottomLen = 0;
int LenDif = 0;
int SumLen = 0;
int TopIn = 0;
int BottomIn = 0;
Console.WriteLine("Doing Subtraction\n");
Console.Write("Enter the First Number: ");
In1 = Console.ReadLine();
Console.Write("Enter the Second Number: ");
In2 = Console.ReadLine();
{
for (int i = 0; i < TopLen; i++)
{
if (In1[i] < In2[i]) ;
Top[i] = In2[i] - '0';
}
LenDif = TopLen - BottomLen;
for (int i = 0; i < LenDif; i++)
{
Bottom[i] = 0;
}
for (int i = 0; i < BottomLen; i++)
{
Bottom[i + LenDif] = In1[i] - '0';
}
}
else
{
TopLen = In1.Length;
BottomLen = In2.Length;
for (int i = 0; i < TopLen; i++)
{
Top[i] = In1[i] - '0';
}
LenDif = TopLen - BottomLen;
for (int i = 0; i < LenDif; i++)
{
Bottom[i] = 0;
}
for (int i = 0; i < BottomLen; i++)
{
Bottom[i + LenDif] = In2[i] - '0';
}
}
for (int i = TopLen -1; i >= 0; i--)
{
if (In1[i] == In2[i])
{
Out = 0;
}
else
{
if (BottomIn == 0)
{
Out = Top[i];
}
}
else
{
if (TopIn == 0)
{
Bottom[i] = Out;
}
}
}
for (int i = TopLen -1 -BottomLen)
{
if(i > TopLen -1 -BottomLen)
{
Dif[i] = Top[i] - Bottom[i];
if (Top[i] == 0)
{
borrow = 1;
Top[i] = 10;
Top[i] -= 9;
}
else
{
borrow = 0;
}
}