[英]C# loops about exponential numbers
I am new on C#, i just learned loops.我是 C# 的新手,我刚刚学习了循环。
I want to write loops that run this.我想编写运行它的循环。 (75 times)
(75次)
I tried this way.我试过这种方式。
for (int i = 1; i <= 75; i++)
{
int sum = 0;
for (int p = 1; p <= i+1; p++)
{
Math.Pow(p, (i + 1));
sum = sum + p;
}
Console.WriteLine(sum);
}
Where am I doing wrong and how should I do about it?我在哪里做错了,我应该怎么做?
This is what you're looking for.这就是你要找的。
for (int power = 1; power <= 75; power++)
{
double sum = 0;
for (int baseNum = 1; baseNum <= power; baseNum++)
{
sum += Math.Pow(baseNum, power);
}
Console.WriteLine(sum);
}
Pow will not modify the value of p. Pow 不会修改 p 的值。 You need to get the returned value into another variable.
您需要将返回值放入另一个变量中。 pp for example.
以pp为例。
pp = Math.Pow(p, ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.