How to print 1 to 100 without any looping using C#

后端 未结 28 1518
天命终不由人
天命终不由人 2020-12-22 19:30

I am trying to print numbers from 1 to 100 without using loops, using C#. Any clues?

28条回答
  •  佛祖请我去吃肉
    2020-12-22 19:58

    public void Main()
    {
      printNumber(1);
    }
    
    private void printNumber(int x)
    {
      Console.WriteLine(x.ToString());
      if(x<101)
      {
        x+=1;
        printNumber(x);
      }
    }
    

提交回复
热议问题