Esempio n. 1
0
 public static BigInt Sub(BigInt a, BigInt b)
 {
     return(null);
 }
Esempio n. 2
0
        public static BigInt Sum(BigInt a, BigInt b)
        {
            int[]  result;
            BigInt c;
            int    al = a.Length, bl = b.Length;

            if (al == bl)
            {
                result = new int[al + 1];
                for (int i = 0; i < al; i++)
                {
                    if (result[i] + a.Digits[i] + b.Digits[i] > 9)
                    {
                        result[i]      = (result[i] + a.Digits[i] + b.Digits[i]) % 10;
                        result[i + 1] += 1;
                    }
                    else
                    {
                        result[i] += a.Digits[i] + b.Digits[i];
                    }
                }
                c = new BigInt(result);
                return(c);
            }
            else
            {
                int max, min;

                if (al > bl)
                {
                    max = al;
                    min = bl;
                }
                else
                {
                    max = bl;
                    min = bl;
                }
                result = new int[max];
                for (int i = 0; i < min; i++)
                {
                    if (result[i] + a.Digits[i] + b.Digits[i] > 9)
                    {
                        result[i]      = (result[i] + a.Digits[i] + b.Digits[i]) % 10;
                        result[i + 1] += 1;
                    }
                }
                if (al > bl)
                {
                    for (int i = min; i < max; i++)
                    {
                        result[i] += a.Digits[i];
                    }
                }
                else
                {
                    for (int i = min; i < max; i++)
                    {
                        result[i] += b.Digits[i];
                    }
                }
                c = new BigInt(result);
            }
            return(c);
        }