Note :This post is first published on Mar-2013 in my previous blog Techkindle. Moving the content here.
In some interviews we may get a question like print certain numbers without using any loops.There are many approaches to accomplish this task. Here i am giving two of the approaches
With recursion
With goto statement
With Recursion
void PrintWithRecursion(int fromNumber, int toNumber)
{
if (fromNumber <= toNumber)
{
Console.Write(fromNumber + " ");
fromNumber++;
PrintWithRecursion(fromNumber, toNumber);
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters