CSharp · Console
// Write a function that prints integer n>0 assuming that we can only print single
// decimal digit using Print(d) command that accepts integer argument in range 0..9.
using System;
using System.Diagnostics;
public class Program
{
// d in the range 0...9
static public void Print(int d)
{
Trace.Assert(0 <= d && d <= 9);
Console.Write(d);
}
// n >= 0
// prints all decimal digits of n for n>0
// prints nothing for n=0
static public void PrintDecimal(int n)
{
if (n != 0)
{
PrintDecimal(n / 10); // number of digits in parameter decreases by 1
Print(n % 10);
}
}
static public void Main()
{
Console.Write("Enter the integer number: ");
PrintDecimal(Convert.ToInt32(Console.ReadLine()));
}
}