Search code examples
c#recursion

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


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


Solution

  • Recursion maybe?

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