May 20, 2020

How to printing 1 232 34543 in triangle in C#.

How to printing 1 232 34543 in triangle in c#.

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

how to display 1 232 34543 in triangle in C#

Sample Solution

C# Sharp Code

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int loop, c, num, no;
            Console.Write("Enter  Number -> ");
            no = Convert.ToInt32(Console.ReadLine());
            for (loop = 1; loop <= no; loop++)
            {
                num = loop;
                for (c = 1; c <= no - loop; c++)
                {
                    Console.Write(" ");
                }

                for (c = 1; c <= loop; c++)
                {
                    Console.Write(num);
                    num++;
                }
                num--;
                num--;
                for (c = 1; c < loop; c++)
                {
                    Console.Write(num);
                    num--;
                }

                Console.WriteLine("\t");
            }
            Console.ReadLine();
        }
    }
}

                                                                    Sample Output

      How to printing 1 232 34543 in triangle in c#


No comments:

Post a Comment