C#递归1~100的累加

 1  public static int Accum(int m, int n)
 2         {
 3             //对于接受的参数,要考虑m >n,m=n,m<n三种情况。
 4             if (m < n)
 5             {
 6                 return (m + Accum(++m, n)); //如果m<n,返回“m”加上“m+1到n累加的和”
 7             }
 8             else
 9             {
10                 if (m > n)
11                 {
12                     return (m + Accum(--m, n)); //如果m.n,返回“m”加上“m-1到n累加的和”
13                 }
14                 else
15                 {
16                     return n; //如果m=n,直接返回n,这是递归的关键。
17                 }
18 
19             }
20         }
 public static int returnsum(int index)
        {
            if (index != 0)
            {
                if (index == 1)
                {
                    return index;
                }
                else
                {
                    return index + returnsum(index - 1);
                }
            }
            else
            {
                return index;
            }
        }