编程实现将一个正整数分解为质因数。例如:输入90,打印出90=233*5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _3_5
{
class Program
{
static int Main(string[] args)
{
for(; ; )
{
Console.WriteLine("请输入一个正整数:");
int zhishu(int a)
{
int t = 0;
for (int i = 2; i <= a; i++)
{
if (a % i == 0)
t++;
}
if (t == 1)
return 1;
else
return 0;
}
string fenjie(int a)
{
int i = 2;
string s = a.ToString() + "=";
for (; i <= a; i++)
if (a % i == 0)
if (zhishu(i) == 1)
{
if (i == a)
s += i.ToString();
else
{
s += i.ToString() + "*";
a = a / i;
i = 1;
}
}
if (zhishu(a) != 1)
s = "该数不能被完全分解为质因数\r\n";
return s;
}
int b = int.Parse(Console.ReadLine());
Console.WriteLine(fenjie(b));
//Console.ReadLine();
Console.WriteLine("退出请输入0 继续请输入1");
int c =int.Parse( Console.ReadLine());
if (c == 0)
return 0;
} }
}
}