Floyed’s Triangle

write a program to print Floyed’s Triangle

Floyd’s triangle is a right-angled triangular array of natural numbers

For example:

Input:
3

Output:
1
2	3
4	5	6

Solution:


using System;

namespace FloyedTriangle
{
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Enter a number:");
            var rows = Convert.ToInt32(Console.ReadLine());

            var k = 1;
            for (var i = 1; i <= rows; i++)
            {
                for (var j = 1; j < i + 1; j++)
                {
                    Console.Write(k++ + "\t");
                }

                Console.Write("\n");
            }
            Console.ReadLine();
        }
    }
}

Leave a Reply

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