skipter icon

C# Fundamentals - Triangle of Nums / Methods and loops

skipter | PRO | 06/13/17 10:54:57 AM UTC | 0 ⭐ | 375 👁️ | Never ⏰ | []
C# |

760 B

|

None

|

0 👍

/

0 👎

using System;
namespace DataBytes___Lab
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            PrintTriangle(n);
        }   
        static void PrintLineNumbers(int start, int end)
        {
            for (int i = start; i <= end; i++)
            {
                Console.Write(i + " ");
            }
            Console.WriteLine();
        }
        static void PrintTriangle(int n)
        {
            for (int line = 1; line <= n; line++)
            {
                PrintLineNumbers(1, line);
            }
            for (int line = n - 1; line >= 1; line--)
            {
                PrintLineNumbers(1, line);
            }
        }
    }
}

Comments