C# Program to Print Floyd?s Triangle
Posted by Superadmin on August 15 2022 15:22:00

C# Program to Print Floyd’s Triangle

 

 

This is a C# Program to display floyd’s triangle with a numeric mode.

Problem Description

This C# Program Displays Floyd’s Triangle with a Numeric Mode.

Problem Solution

Here the numbers are displayed in the form of a triangle.

Program/Source Code

Here is source code of the C# Program to Display Floyd’s Triangle with a Numeric Mode. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program to Display Floyd's Triangle with an Numeric Mode
 */
using System;
class Program
{
    static void Main(string[] args)
    {
 
        int i, j, k = 1;
       for (i = 1; i <= 10; i++)
        {
            for (j = 1; j < i + 1; j++)
            {
                Console.Write(k++ + " ");
            }
 
            Console.Write("\n");
        }
        Console.ReadLine();
    }
}
Program Explanation

This C# program is used to print Floyd’s triangle. Floyd’s triangle is a right-angled triangular array of natural numbers. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner: 1. Number of rows of Floyd’s triangle to print is entered by the user. For loop is used to print Floyd’s triangle in a numeric mode.

 
Runtime Test Cases
 
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55