Exemple #1
0
        //so do dai ,gia tri cua tung phan tu trong mang
        public int Compareto(SoLon b)
        {
            var ar = this.arr;
            var br = b.arr;

            if (ar.Length > br.Length)
            {
                return(1);
            }
            else if (ar.Length < br.Length)
            {
                return(-1);
            }
            else
            {
                for (int i = 0; i < ar.Length; i++)
                {
                    if (ar[i] > br[i])
                    {
                        return(1);
                    }
                    if (ar[i] < br[i])
                    {
                        return(-1);
                    }
                }
                return(0);
            }
        }
Exemple #2
0
        //phep tru
        static SoLon Tru(SoLon a, SoLon b)
        {
            if (b.ToString() == "0")
            {
                return(a);
            }
            else if (a.ToString() == "0")
            {
                return(b);
            }
            var max = Math.Max(a.arr.Length, b.arr.Length);


            var mangLon = MakeSameLength(a.arr, max);
            var mangNho = MakeSameLength(b.arr, max);

            if (a.Compareto(b) == -1)
            {
                mangLon = b.arr;
                mangNho = a.arr;
            }
            var ret = TruMang(mangLon, mangNho);

            return(new SoLon(ret));
        }
Exemple #3
0
        //phep gia thừa
        public SoLon GiaiThua()
        {
            var a   = this;
            var ret = new SoLon("1");

            while (!a.Equals(new SoLon("1")))
            {
                ret = ret * a;
                a   = a - new SoLon("1");
            }
            return(ret);
        }
Exemple #4
0
        //phep mu
        static SoLon Mu(SoLon a, SoLon mu)
        {
            var ret   = new SoLon("1");
            var donVi = new SoLon("1");
            var dem   = new SoLon("0");

            while (!dem.Equals(mu))
            {
                ret = ret * a;
                dem = dem + donVi;
            }
            return(ret);
        }
Exemple #5
0
        //phep cong
        static SoLon Cong(SoLon a, SoLon b)
        {
            if (a.ToString() == "0")
            {
                return(b);
            }
            if (b.ToString() == "0")
            {
                return(a);
            }
            var ret = CongMang(a.arr, b.arr);

            return(new SoLon(ret));
        }
Exemple #6
0
        // phep nhan
        static SoLon Nhan(SoLon a, SoLon b)
        {
            var mangLon = a.arr;
            var mangNho = KiemTraMangKhac0(b.arr);

            if (a.Compareto(b) == -1)
            {
                mangLon = b.arr;
                mangNho = KiemTraMangKhac0(a.arr);
            }
            var ret = new int[mangNho.Length];

            for (int i = 0; i < mangNho.Length; i++)
            {
                var x = NhanSoVoiMang(mangNho[mangNho.Length - 1 - i], mangLon);
                if (i > 0)
                {
                    x = Them10DonViChoSo(x, i);
                }
                ret = CongMang(x, ret);
            }

            return(new SoLon(ret.ToArray()));
        }