Today we will write a program for printing a given string’s in triangle.

For Example

input : Independence

Output

image

Code

For First Image

        public static void PrintStringInTriangle(this string input)
        {
            int length = input.Length;

            for (int i = 0; i < length; i++)
            {
                for (int spaceCounter =0; spaceCounter <=length-i; spaceCounter++)
                {
                    Console.Write(" ");
                }
                for (int charCounter = 0; charCounter <=i; charCounter++)
                {
                    Console.Write(input[charCounter]);
                    Console.Write(" ");
                }
                Console.WriteLine("");
            }


        }

For Second Image

        public static void PrintStringInLeftTriangle(this string input)
        {
            int length = input.Length;

            for (int i = 0; i < length; i++)
            {
                for (int spaceCounter = 0; spaceCounter <= length - i; spaceCounter++)
                {
                    Console.Write(" ");
                }
                for (int charCounter = 0; charCounter <= i; charCounter++)
                {
                    Console.Write(input[charCounter]);
                     
                }
                Console.WriteLine("");
            }


        }

For Third Image

        public static void PrintStringInRightTriangle(this string input)
        {
            int length = input.Length;

            for (int i = 0; i < length; i++)
            {
                for (int spaceCounter = 0; spaceCounter <= length; spaceCounter++)
                {
                    Console.Write(" ");
                }
                for (int charCounter = 0; charCounter <= i; charCounter++)
                {
                    Console.Write(input[charCounter]);

                }
                Console.WriteLine("");
            }


        }