How to print text diagonally from left to right recursively in C#

1 Answer

0 votes
using System;

class Program
{
    static void printTextDiagonallyRecursivelyLTR(string spaces, string text) {
        if (text.Length > 0) {
            Console.WriteLine(spaces + text[0]);
            printTextDiagonallyRecursivelyLTR(spaces + " ", text.Substring(1));
        }
    }

    static void Main()
    {
        printTextDiagonallyRecursivelyLTR("", "HELLO WORLD");
    }
}


/*
run:

H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D

*/

 



answered Apr 8 by avibootz

Related questions

...