-4
我写了代码,它应该告诉P的最小值是什么,它会使整个sqrt成为一个自然数。 问题在于,每当它到达P = K的部分时,循环停止并表示这是相同的值。 例如:4号它完美,但对于5它说,他们是平等的,但在45开方是不是自然数在C中寻找一个自然数#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
int k, p = 0;
double final;
Console.WriteLine("Please enter the value of K ");
k = int.Parse(Console.ReadLine());
final = System.Math.Sqrt(4 * k + System.Math.Pow(p, 2));
while (final - (int)(final) != 0&&p!=k)
{
final = System.Math.Sqrt(4 * k + System.Math.Pow(p, 2));
p++;
}
Console.WriteLine("k is {0}, and P is {1}", k, p);
}
}
}
代码,以什么语言写不会做你认为它*有*做,直到你*让*它做。 –
代码是由您编写的,如果它不起作用... – dcg
更像是第8层上的错误 – Fabiano