使用递归功能?

Amm*_*aja 1 c# c++

我想创建一个显示从1到100和100到1的数字的函数我很困惑,我怎么能用递归来做到这一点?

我不想使用任何其他循环这样做.请提示我并忽略我的询问方式,因为我是c ++和c#的新手.

Hen*_*man 5

void Print100(int n)
{
   if (n > 100)
   {
       Console.WriteLine();  // cosmetic
       return;               // stop recursing
   }

   Console.WriteLine(n);     // 1-100
   Print100(n+1);            // recurse
   Console.WriteLine(n);     // 100-1, on the way out
}


void Main()
{
    Print100(1);
}
Run Code Online (Sandbox Code Playgroud)