huanhuan5555 @ 2024-11-07 16:51:43
namespace ConsoleApp7
{
internal class Program
{
static void Main(string[] args)
{
double Sn = 0;
double n=0;
n = GetSn(1);
Console.WriteLine(n);
int GetSn(int x)
{
int i = 1;
for (i = 1; i < 100000; i++)
{
Sn = Sn +(double) 1.0 / i;
if (Sn > x)
break;
}
return i;
}
}
}
}
by Estrella_Explore @ 2024-11-07 16:55:54
@huanhuan5555
Java?
在 luogu 问 java 的有关问题一般不会有回答的(
by holmeboo @ 2024-11-07 17:02:46
这不显然用while循环嘛?
by MANGO_GANG @ 2024-11-07 17:04:37
你把函数写在Main里面咋能对嘛(
剩下的不清楚,不是很懂java
by PVYCVJ @ 2024-11-07 17:19:10
C#?
函数套函数是比较新的功能,可能编译器会不支持,何况这题也不需要这个功能
以及一些其他问题……
by iqiqiqiqiqiqiqiq @ 2024-11-08 23:06:05
@huanhuan5555 请标明语言,而且Md不太对
by huanhuan5555 @ 2024-11-09 15:47:54
@iqiqiqiqiqiqiqiq 是c#语言
by huanhuan5555 @ 2024-11-09 15:48:54
@Estrella_Explore 不是的,是c#语言
by huanhuan5555 @ 2024-11-09 16:41:12
@PVYCVJ ,我用while做也只有20分,请帮我看看问题在哪里行吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
internal class Program
{
static void Main(string[] args)
{
Test result= new Test();
int n = result.GetSn(1);
Console.WriteLine(n);
Console.ReadKey();
}
}
class Test
{
public double Sn = 0;
public int GetSn(int k)
{
int n=0;
while (Sn <= k)
{
n++;
Sn = Sn +(double) 1.0 / n;
}
return n;
}
}
}
by PVYCVJ @ 2024-11-10 04:18:23
@huanhuan5555 你读取
by huanhuan5555 @ 2024-11-10 16:05:37
@PVYCVJ ,不是只要输出n吗?还和k有关系吗