using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MyTest
{
internal class Program
{
static void Main(string[] args)
{
Calculator c = new Calculator();
int Sum1 = c.SumFrom1Tox(100);
int Sum2 = c.SumDg(100);
Console.WriteLine(Sum1);
Console.WriteLine(Sum2);
Console.ReadLine();
}
}class Calculator
{
public int SumFrom1Tox(int x)
{
int Sum=0;
for (int i = 1; i < x+1; i++) //循坏
{
Sum = Sum + i;
}
return Sum;
}
public int SumDg(int x)
{
if (x == 1)
{
return 1;
}
else
{
int Sum=x+ SumDg(x - 1); //递归
return Sum;
}
}
}
}
06-29
1227
06-03
11-13
2745
08-13
2010