Print all numbers between 1 to N without using any loop | 4 methods

Write a program to print all numbers between 1 to N without using loop.

Method 1: (Using static variable in recursive main())

We can call main() function recursively and with each call we print next element from the series. To store information about previous element printed, we use a static variable (Note that a global variable will also work fine).