How to display 1 121 12321 in triangle in C#.
In this article, we will learn how to display 1 121 12321 in triangle below pattern in c#.
Sample Solution
C# Sharp Codeusing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class program { static void Main(string[] args) { int numberoflayer, space, number; Console.WriteLine("Enter Number "); numberoflayer = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("print parmid"); for (int i = 1; i <= numberoflayer; i++) { for (space = 1; space <= (numberoflayer - i); space++) Console.Write(" "); for (number = 1; number <= i; number++) Console.Write(number); for (number = i - 1; number >= 1; number--) Console.Write(number); Console.WriteLine(); } Console.ReadLine(); } } }
No comments:
Post a Comment