我想创建一个C# 2005程序来计算给定输入的质因数。我想使用基本且最简单的方法,不需要为此创建方法或数组等内容,只需使用简单的模数即可。是否有代码可以满足我的要求?
以下是用于查找简单因子的代码,我需要修改此代码以计算质因数。
以下是用于查找简单因子的代码,我需要修改此代码以计算质因数。
class Program
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Please enter your integer: ");
a = int.Parse(Console.ReadLine());
for (b = 1; b <= a; b++)
{
if (a % b == 0)
{
Console.WriteLine(b + " is a factor of " + a);
}
}
Console.ReadLine();
}
}
Console.Write(factor);
吗?你可能想在数字之间写一个空格Console.Write(' ');
,或者使用Console.WriteLine,或其他方法。 - Rup