Monday, 30 December 2013

Triangle Pattern Example using Console Application in C#

Ans:-

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

namespace Logicals
{
    class TrianglePattern
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Number of Rows u want Only..");
            int num = int.Parse(Console.ReadLine());
            for (int i = 1; i <= num; i++)
            {
                for (int space = 1; space <= num - i; space++)
                {
                    Console.Write(" ");
                }
                for (int j = 1; j <= 2 * i - 1; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }

                Console.ReadLine();
        }
    }
}

No comments:

Post a Comment