分解质因数
private static void 分解质因数()
{
StringBuilder sb = new StringBuilder();
int n,inputNumb;
Console.WriteLine("please input a number:");
inputNumb = Convert.ToInt32(Console.ReadLine());
n = inputNumb;
for (int i = 2; i <= n; i++) //循环被除数
{
while (n != i)
{
if (n % i == 0) //整除即可//质数
{
sb.Append(i+"*");
n = n / i; //新的除数
}
else break;
}
}
sb.Append(n);
Console.WriteLine("{0}分解质因数为:{1}",inputNumb,sb.ToString().TrimEnd(new char[]{'*'}));
}