hello my friends I need a little help over here :
im workin on a calculator that should provide the user with these services:
• Read a big integer number up to 300 ( use arrays ) .
• Sum two big integer numbers (with using the carry).
• Product two big integer numbers (with using the carry).
• Write a big Integer number.
so this is wat i did
class Program
{
static void Main(string[] args)
{
//inputting the two numbers .
string number1, number2;
int sumsize, p;
number1 = Console.ReadLine();
number2 = Console.ReadLine();
//modifying the numbers to be from the same length .
/*i added one to the sum array size(sumsize) to avoid
the over flow */
if (number1.Length > number2.Length)
{
number2 = number2.PadLeft(number1.Length, '0');
sumsize = number1.Length+1;
p = number1.Length;
}
else
{
number1 = number1.PadLeft(number2.Length, '0');
sumsize = number2.Length+1;
p = number2.Length;
}
//declaring the two arrays and filling them with characters .
/* the input is string so when converting it to int i found that
i should subtract 48 to get the right result */
int[] arr1 = new int[number1.Length];
for (int i = 0; i < number1.Length; i++)
arr1[i] = Convert.ToInt32(number1[i] - 48);
int[] arr2 = new int[number2.Length];
for (int i = 0; i < number2.Length; i++)
arr2[i] = Convert.ToInt32(number2[i] - 48);
//displaying the two arrays .
Console.WriteLine("\n1ST.Number is: \n");
for (int i = 0; i < number1.Length; i++)
Console.Write(arr1[i]);
Console.WriteLine("\n\n2ND.Number is: \n");
for (int i = 0; i < number2.Length; i++)
Console.Write(arr2[i]);
Console.WriteLine();
// till here everything is workin properly .. then -->
int[] sum = new int[sumsize];
int carry = 0;
int holder;
// the sum
for (int i = p-1; i >=0; i--)
{
holder=arr1[i] + arr2[i] + carry;
if (holder < 10)
{
sum[sumsize-1] = arr1[i] + arr2[i] + carry;
carry = 0;
}
else
{
sum[sumsize-1] = holder % 10;
carry = 1;
}
sumsize--;
}
Console.WriteLine("sum is=");
for(int i=0;i<sumsize;i++)
Console.Write(sum[i]);
}
}
}
unfortunately its not workin right,
so please any help