Skip to content

Commit 7892593

Browse files
authored
Merge pull request ephremdeme#233 from grvkr777/add-PascalTriangle-in-c-sharp
Add pascal triangle in C#
2 parents 7bec626 + 88d5c46 commit 7892593

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
void printPascal(int n)
2+
{
3+
4+
int arr[n][n];
5+
6+
7+
for (int line = 0; line < n; line++)
8+
{
9+
10+
for (int i = 0; i <= line; i++)
11+
{
12+
13+
if (line == i || i == 0)
14+
arr[line][i] = 1;
15+
16+
else
17+
arr[line][i] = arr[line-1][i-1] + arr[line-1][i];
18+
printf("%d ", arr[line][i]);
19+
}
20+
printf("\n");
21+
}
22+
}
23+
24+
int main()
25+
{
26+
int n = 5;
27+
printPascal(n);
28+
return 0;
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
using System;
3+
4+
class GAURAV
5+
{
6+
public static void printPascal(int n)
7+
{
8+
9+
int[,] arr = new int[n, n];
10+
11+
12+
for (int line = 0; line < n; line++)
13+
{
14+
15+
for (int i = 0; i <= line; i++)
16+
{
17+
18+
if (line == i || i == 0)
19+
arr[line, i] = 1;
20+
else
21+
arr[line, i] = arr[line - 1, i - 1] +
22+
arr[line - 1, i];
23+
Console.Write(arr[line, i]);
24+
}
25+
Console.WriteLine("");
26+
}
27+
}
28+
29+
30+
public static void Main ()
31+
{
32+
int n = 5;
33+
printPascal(n);
34+
}
35+
}
36+

0 commit comments

Comments
 (0)