May 13, 2020

How to printing 1 123 12345 in triangle in c#

How to printing 1 123 12345 in triangle in c#.

In this article, we will learn how to display 1 123 12345 in triangle below pattern in c#.

How to display number in triangle in c#

Sample Solution

C# Sharp Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int v;//the number of spaces
            Console.WriteLine("Enter a number ");
            v = Convert.ToInt32(Console.ReadLine());
            //20 = how much lines
            for (int i = 1; i <= v; i++)
            {
                //loop to print spaces
                for (int j = 1; j < v; j++)
                {
                    Console.Write(" ");
                }

                v = v - 1;
                //loop to print stars
                for (int t = 1; t < i * 2; t++)
                {
                    Console.Write(t);
                }
                //create a new Line
                Console.WriteLine();
            }

            Console.ReadLine();
        }
    }
}


                                                            Sample Output


How to printing 1 123 12345 in triangle in c#




No comments:

Post a Comment