示例#1
0
        public static Biginteger operator +(Biginteger First, Biginteger Second)
        {
            int CountOfFirst = First.amount;
            int CountOfSecond = Second.amount;
            int MaxCount = Math.Max(CountOfFirst, CountOfSecond);
            char[] Result = new char[1000];
            int memory = 0;
            for (int i=0; i<MaxCount; i++)
            {
                if (CountOfFirst <= i)
                {
                    if (memory == 1)
                    {
                        Result[MaxCount - i] = (Convert.ToChar((memory + Convert.ToInt32(Second.str[CountOfSecond - i - 1] - '0'))));
                        memory = 0;
                        Result[MaxCount - i] += '0';
                    }
                    else
                    {
                        Result[MaxCount - i] = Convert.ToChar(Convert.ToInt32(Second.str[CountOfSecond - i - 1]) - '0');
                        Result[MaxCount - i] += '0';
                    }
                    //Console.WriteLine(Result[MaxCount - i] + "Fisrt if");
                    continue;
                }
                if (CountOfSecond <= i)
                {
                    if (memory == 1)
                    {
                        if (memory + Convert.ToInt32(First.str[CountOfFirst - i - 1] -'0') >= 10)
                        {
                            memory = 1;
                            Result[MaxCount - i] = Convert.ToChar((Convert.ToInt32(First.str[CountOfFirst - i - 1]))

                        }
                        Result[MaxCount - i] = Convert.ToChar((memory + Convert.ToInt32(First.str[CountOfFirst - i - 1]) + '0'));
                        memory = 0;
                        Result[MaxCount - i] -= '0';
                        //Console.WriteLine(Convert.ToChar(8+ '1'));
                    }
                    else
                    {
                        Result[MaxCount - i] = Convert.ToChar((Convert.ToInt32(First.str[CountOfFirst - i - 1]) + '0'));
                        Result[MaxCount - i] -= '0';
                        //Console.WriteLine(Result[MaxCount - i] + " else");

                    }
                    continue;
                }
                if (memory + Convert.ToInt32(First.str[CountOfFirst-i-1] - '0') + Convert.ToInt32(Second.str[CountOfSecond-i-1]-'0') >= 10)
                {
                    Result[MaxCount - i] = Convert.ToChar((memory + Convert.ToInt32(First.str[CountOfFirst - i - 1] - '0') + Convert.ToInt32(Second.str[CountOfSecond - i - 1] - '0'))%10);
                    memory = 1;
                    Result[MaxCount - i] = Convert.ToChar(Result[MaxCount - i] + '0');
                }
                else
                {
                    Result[MaxCount - i] = Convert.ToChar(memory + Convert.ToInt32(First.str[CountOfFirst - i - 1] - '0') + Convert.ToInt32(Second.str[CountOfSecond - i - 1] - '0'));
                    memory = 0;
                    Result[MaxCount - i] = Convert.ToChar(Result[MaxCount - i] + '0');
                }
                //Console.WriteLine(Result[MaxCount - i]);
            }
            string Converting = "";
            if (memory == 1)
            {
                Result[0] = '1';
            }
            else
                Result[0] = '0';
            for(int i=0; i<=MaxCount; i++)
            {
                Converting += Result[i];
            }
            Biginteger final = new Biginteger(Converting);
            return final;
        }
示例#2
0
 static void Main(string[] args)
 {
     Console.WriteLine("Enter two big number");
     string FirstString = Console.ReadLine();
     string SecondString = Console.ReadLine();
     Biginteger FS = new Biginteger(FirstString);
     Biginteger SS = new Biginteger(SecondString);
     Biginteger Result = FS + SS;
     Console.WriteLine(Result);
     Console.ReadKey();
 }