楼上代码是对的,我复制的给你改了一下,下面是整段代码,满意的话把分给楼上的
protected void Page_Load(object sender, EventArgs e)
{
//输出查看
Response.Write(Sum(100));
}
///
/// 求1-n的和
///
///
///
public int Sum(int n)
{
int Sum = 0;
for (int i = 1; i <= n; i++)
{
Sum += i;
}
return Sum;
}
int aa=0;
for (int i = 1; i <= 100; i++)
{
aa = aa+i;
}
Console.Write(aa);
Console.ReadLine();
protected int Sum()
{
int Sum100 = 0;
for (int i = 1; i <= 100; i++)
{
Sum100 += i;
}
return Sum100;
}
int j=101;
int i=100/2;
int sum;
sum=i*j搞定
......楼上是c#语言,你直接调用Sum方法就成了