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.

advertisement
advertisement
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

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.