C# Program to print Number Triangle

In this C# program, we will take input (Number of rows) from the user and print the Number triangle based on the number of rows input by the user.

C# Program to print Number Triangle Code:

 private static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            int i, j, k, l, n;
            Console.Write("Enter the number of rows:");
            n = int.Parse(Console.ReadLine());
            for (i = 1; i <= n; i++)
            {
                for (j = 1; j <= n - i; j++)
                {
                    Console.Write(" ");
                }
                for (k = 1; k <= i; k++)
                {
                    Console.Write(k);
                }
                for (l = i - 1; l >= 1; l--)
                {
                    Console.Write(l);
                }
                Console.Write("\n");
            }
            Console.ReadLine();
        } 

C# Program to print Number Triangle Output:

C#-Program-to-print-Number-Triangle

C#-Program-to-print-Number-Triangle

 
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
5 + 8 =
 

About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024 CodingFusion
50+ C# Programs for beginners to practice