首页 > Windows开发 > 详细

C#分解质因数

时间:2018-12-16 18:38:52      阅读:169      评论:0      收藏:0      [点我收藏+]

 

 

 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace app
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            
            string n1 = Convert.ToString(n);
            int i=2;
            string str = "";
            if (n < 2)
            {
                Console.Write(n);
            }
            while (i <= n)
            {
                while (n % i == 0)
                {
                    n = n / i;

                    str += i;
                    if (i<=n)
                    {
                        str += "x";
                    }
                }
                i++;        

            }
                Console.WriteLine(n1+ "=" + str);
                Console.ReadKey();
            }
        
        }
    
}

 

C#分解质因数

原文:https://www.cnblogs.com/tianranhui/p/10127465.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!