Here are the codes: (How to print 1 to 100 without any looping using C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class Program { static void printNumber(int condition,int start=1) { Console.WriteLine(start); //Console.Write("{0,-5} ",start); if (start < condition) printNumber( condition, start + 1); } static void Main(string[] args) { int N = 100; printNumber(N); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 |
1 2 3 4 ... ... 99 100 |