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

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

    Recursion maybe?

    public static void PrintNext(i) {
        if (i <= 100) {
            Console.Write(i + " ");
            PrintNext(i + 1);
        }
    }
    
    public static void Main() {
        PrintNext(1);
    }
    

提交回复
热议问题