Print 1-10 numbers without using any Conditional Loop (without using loop ,for Loop, while Loop, do-while Loop)
There are a few ways for solving the problem but I solved this problem with recursive method.
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 = 10; printNumber(N); Console.ReadLine(); } } |
Output:
You can find more similar examples of programming for this programming language in the site.