亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#實(shí)現(xiàn)大數(shù)字運(yùn)算的實(shí)例代碼

 更新時(shí)間:2013年10月19日 15:09:59   作者:  
這篇文章介紹了C#實(shí)現(xiàn)大數(shù)字運(yùn)算的實(shí)例代碼,有需要的朋友可以參考一下

C#實(shí)現(xiàn)大數(shù)字的運(yùn)算
1、添加引用:System.Numerics.dll

2、添加命名空間:using System.Numerics;

3、實(shí)例:

3.1判斷一個(gè)數(shù)字是不是質(zhì)數(shù) 

復(fù)制代碼 代碼如下:

static void Main(string[] args)
        {
            Console.WriteLine("請(qǐng)輸入一個(gè)很大的數(shù)字:");
            string bigNumber = Console.ReadLine();
            BigInteger bigInteger = BigInteger.Parse(bigNumber);
            bool isNumber=false;
            for (BigInteger i = 2; i < BigInteger.Pow(bigInteger, 2);i++ )
            {
                if (bigInteger % i == 0)
                {
                    isNumber = true;
                    break;
                }
            }
            if (isNumber)
            {
                Console.WriteLine("不是質(zhì)數(shù)");
            }
            else
            {
                Console.WriteLine("是質(zhì)數(shù)");
            }
            Console.ReadLine();
        }

3.2實(shí)現(xiàn)兩個(gè)大數(shù)的加減乘除

復(fù)制代碼 代碼如下:

static void Main(string[] args)
        {
            Console.Write("請(qǐng)輸入第一個(gè)大數(shù)字:");
            string bigNum1 = Console.ReadLine();
            BigInteger bigInt1 = BigInteger.Parse(bigNum1);

            Console.Write("請(qǐng)輸入第二個(gè)大數(shù)字:");
            string bigNum2 = Console.ReadLine();
            BigInteger bigInt2 = BigInteger.Parse(bigNum2);
            Console.Write(Environment.NewLine);

            BigInteger addNum = bigInt1 + bigInt2;
            BigInteger subNum = bigInt1 - bigInt2;
            BigInteger purNum = bigInt1 * bigInt2;
            BigInteger divNum = bigInt1 / bigInt2;

            Console.WriteLine("兩大數(shù)相加結(jié)果為:{0}",addNum);
            Console.WriteLine("兩大數(shù)相減結(jié)果為:{0}",subNum);
            Console.WriteLine("兩大數(shù)相乘結(jié)果為:{0}",purNum);
            Console.WriteLine("兩大數(shù)相除結(jié)果為:{0}",divNum);

            Console.ReadLine();
        }

相關(guān)文章

最新評(píng)論