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

后端 未结 28 1481
天命终不由人
天命终不由人 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 20:09

    By the time I answer this, someone will already have it, so here it is anyway, with credit to Caleb:

    void Main()
    {
        print(0, 100);
    }
    
    public void print(int x, int limit)
    {
        Console.WriteLine(++x);
        if(x != limit)
            print(x, limit);
    }
    

提交回复
热议问题