To write the C# program to print Pascal's triangle.
Initialize the neccessary attributes.
Get the no. of rows from the user.
Using for loop print the rows, columns and spaces at required places.
Apply if condition to print 1.
If the condition fails, print the number using the formula. value=value*(i-j+1)/j.
DEVELOPED BY : VAISHNAVI S
REG NO : 212222230165
using System;
public class Pattern {
class Example {
public static void Main() {
int rows, c = 1, s, i, j;
rows=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pascal's triangle");
for(i = 0; i<rows; i++) {
for(s = 1; s <= rows-i; s++)
Console.Write(" ");
for(j = 0; j <= i; j++) {
if (j == 0||i == 0)
c = 1;
else
c = c*(i-j+1)/j;
Console.Write(c + " ");
}
Console.WriteLine();
}
}
}
}
Hence, a C# program for a pascal's triangle is executed successfully.