Print n Number n Times Loop

This is a simple loop to print a number starting from 0 to n. The number will be printed n times.

    class Program
    {
        static void Main(string[] args)
        {
            PrintNumebersManyTimesAsNumberItSelf(20);
        }

        /// <summary>
        /// This will print a number strating from zero to length,
        /// The number will be printed as many times as the number itself.
        /// </summary>
        /// <param name="length">Length to stop, will start from 1</param>
        private static void PrintNumebersManyTimesAsNumberItSelf(int length)
        {
            for (int i = 0; i < length + 1; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    Console.Write(i);
                }
            }
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *