Hi a newbie to programming/C# here. Just a question on recursion I encountered. Using recursion, I need to print this series of numbers :
12344321
I know how to do the first portion.
[code]
public static void PrintNumber(int n)
{
if (n==1)
Console.Write(n);
else
{
PrintNumber(n-1);
Console.Write(n);
}
}
[/code]
This will print out 1234, but how do I print the trailing 4321 in the same method using recursion?
AlanPosted Oct 27, 2007, 6:11 PM
Try calling the following method with PrintNumber(1,4):
public static void PrintNumber(int from, int to)
{
Console.Write(from);
if (from < to) PrintNumber(from + 1, to);
Console.Write(from);
}