C# Saved Program: pascaltriangle

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


/*
 *  C# Program to Display Numbers in the form of Triangle
 */
using System;
class Pascal
{
    public static void Main()
    {
        int[,] arr = new int[8, 8];     
        for (int i = 0; i < 8; i++)
        {
            
 
            for (int j = 0; j < i; j++)
            {
                if (j == 0 || i == j)
                {
                    arr[i, j] = 1;
                }
                else
                {
                    arr[i, j] = arr[i - 1, j] + arr[i - 1, j - 1];
                }
                
            }
            Console.WriteLine();
 
        }
        for(int d = 7;d > 0;d++){
            for (int k = 7; k > d; k--)
            {   //For loop to print spaces
                Console.Write(" ");
            }
            for(int s = 0;s >d;s++){
                Console.Write(arr[d, s] + " ");
            }
        }
        Console.ReadLine();
    }
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs