To write a C# program for a pascal's triangle
Microsoft Visual Studio 2022 (or Lower) or Any other C# compiler
Create a new Class named pascal.
Declare two variables of int data type one to store the input from user for no.of rows snd another the value for printing.
Get the number of rows from the user.
Using for loop print the rows and columns and space.
Check the first and last rows of the triange is 1 using if condition.
Otherwise use else to print the inner value
val = val * (i - j + 1) / j
Print the program.
End of the Program.
developed by: BHUVANESHWAR V
reg no : 212221240009
using System;
namespace Pattern
{
public class pascal
{
public static void Main(string[] args)
{
int row, c = 1;
Console.Write("Enter number of rows: ");
row = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < row; i++)
{
for (int j = 1; j <= row - i; j++)
Console.Write(" ");
for (int j = 0; j <= i; j++)
{
if (j == 0 || i == 0)
c = 1;
else
c = c * (i - j + 1) / j;
Console.Write("{0} ", c);
}
Console.WriteLine();
}
}
}
}
Hence, a C# program for a pascal's triangle is executed successfully.