forked from NataSola/HelloCode
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·59 lines (52 loc) · 1.24 KB
/
Copy pathProgram.cs
File metadata and controls
executable file
·59 lines (52 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
int row = 128;
int[,] triangle = new int[row, row];
const int cellWidth = 1;
void FillTriangle()
{
for (int i = 0; i < row; i++)
{
triangle[i, 0] = 1;
triangle[i, i] = 1;
}
for (int i = 2; i < row; i++)
{
for (int j = 1; j <= i; j++)
{
triangle[i, j] =
triangle[i - 1, j - 1] + triangle[i - 1, j];
}
}
}
void PrintTriangle()
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < row; j++)
{
if (triangle[i, j] != 0)
Console.Write($"{triangle[i, j],cellWidth}");
}
Console.WriteLine();
}
}
void Magic()
{
int col = cellWidth * row;
for (int i = 0; i < row; i++)
{
for (int j = 0; j <= i; j++)
{
Console.SetCursorPosition(col, i + 1);
//if (triangle[i, j] != 0) Console.Write($"{triangle[i, j],cellWidth}");
if (triangle[i, j] % 2!= 0) Console.WriteLine("*");
col += cellWidth * 2;
}
col = cellWidth * row - cellWidth * (i + 1);
Console.WriteLine();
}
}
Console.ReadLine();
FillTriangle();
//PrintTriangle();
Console.ReadLine();
Magic();