Display Numbers in the form of Triangle in C# – Programming, Pseudocode Example, C# Programming Example
C# C# Console

Display Numbers in the form of Triangle in C#

In this example, i’ll show you How to display numbers in the form of triangle in C#.

Here is source code of the C# Program to Display Numbers in the form of Triangle. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

In this C# program, we are printing the numbers in the form of triangle. Pascal’s triangle is a triangular array of the binomial coefficients. The program consists of six integer type of variables named i, j, rows, array[][], k and num respectively. Out of this variable i, j and k have been defined to control the for loop, the integer ‘rows’ stores the limit of Pascal’s triangle entered by the user.

As the C program for Pascal’s triangle is executed, it first asks for the value of limit of the triangle. The program assigns ‘rows’ variable value with the value of ‘i’ variable; i.e., number of space with the limit of Pascal’s triangle, for loop in which ‘i’ is the loop control variable. Again, in order to control the space, a nested for loop with ‘k’ as a control variable is used.

Finally, for printing the elements in this program for Pascal’s triangle in C, another nested for loop of control variable ‘j’ has been used. The formula used to generate the numbers of Pascal’s triangle is:
Pascal triangle: array[i][j] = array[i – 1][j – 1] + array[i – 1][j].


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: