c# 问题 编写一个程序,用goto语句建立循环结构,求出1到100之和。

编写一个程序,用goto语句建立循环结构,求出1到100之和。用控制台应用程序编辑,最好有完整代码 谢谢

第1个回答  2010-04-19
namespace Example2
{
class Program
{
static void Main(string[] args)
{

int i = 1;
int sum=0;
lable:
sum += i;
i++;
if (i <= 100)
goto lable;
else
Console.WriteLine("sum={0:d}", sum);
Console.Read();
}
}
}本回答被提问者采纳
第2个回答  2019-11-30
namespace
Example2
{
class
Program
{
static
void
Main(string[]
args)
{
int
i
=
1;
int
sum=0;
lable:
sum
+=
i;
i++;
if
(i
<=
100)
goto
lable;
else
Console.WriteLine("sum={0:d}",
sum);
Console.Read();
}
}
}
第3个回答  2010-04-20
为什么不用FOR?
int i;
for(i = 0;i<=100; i++)
{
i = i + 1;
}
MessageBox.Show(i);
第4个回答  2010-04-19
用FOR不是更好!
相似回答