public static string GetData(double value)
{
string result = string.Empty;
double temp = 0;
for (double i = 0;i <= value;++i)
{
temp = (Math.Pow(i, 3) + 2 * i);
if (temp > value)
{
return result;
}
else
{
result = i.ToString() + "," + temp.ToString();
}
}
return string.Empty;
{
string result = string.Empty;
double temp = 0;
for (double i = 0;i <= value;++i)
{
temp = (Math.Pow(i, 3) + 2 * i);
if (temp > value)
{
return result;
}
else
{
result = i.ToString() + "," + temp.ToString();
}
}
return string.Empty;
}
string result = GetData(135);
Console.WriteLine(result);
Console.Read();
return;
输入:135,输出:5,135
输入:100,输出:4,72(因为100没有,所以输出不大于100的最近值)