-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6251071018_NguyenHuongDuyen_BT15092023.cs
127 lines (113 loc) · 3.29 KB
/
6251071018_NguyenHuongDuyen_BT15092023.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// See https://aka.ms/new-console-template for more information
using System.Data;
internal class Program
{
public static void Main(string[] args)
{
int h = 0;
while (true)
{
Console.WriteLine("Nhap chieu cao h:");
if (!int.TryParse(Console.ReadLine(), out h)
)
{
Console.WriteLine("Nhap sai cu phap! (h la so nguyen >0).\nHay nhap lai.\n");
continue;
}
break;
}
Console.WriteLine("Cac hinh ve voi h = " + h);
Console.WriteLine("\nIncreasing Right Triangle.");
paintIncreasingRightTriangle(h);
Console.WriteLine("\nDecreasing Left Triangle");
paintDecreasingLeftTriangle(h);
Console.WriteLine("\nIncreasing Left Triangle.");
paintIncreasingLeftTriangle(h);
Console.WriteLine("\nDecreasing Right Triangle.");
paintDecreasingRightTriangle(h);
}
private static void paintIncreasingRightTriangle(int h,char drawSymbol = '*', char blankSymbol=' ')
{
var arr = new char[h, h];
for (int i = 0; i < h; i++)
{
for (int j = 0; j < h; j++)
{
if (j <= i)
arr[i, j] = drawSymbol;
else arr[i, j] = blankSymbol;
}
}
for (int i = 0; i < h; i++)
{
for (int j = 0; j < h; j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
}
private static void paintDecreasingLeftTriangle(int h, char drawSymbol = '*', char blankSymbol = ' ')
{
var arr = new char[h, h];
for (int row = 0; row < h; row++)
{
for (int col = 0; col < h; col++)
{
if (row <= col)
arr[row, col] = drawSymbol;
else arr[row, col] = blankSymbol;
}
}
for (int row = 0; row < h; row++)
{
for (int col = 0; col < h; col++)
{
Console.Write(arr[row, col]);
}
Console.WriteLine();
}
}
private static void paintIncreasingLeftTriangle(int h)
{
var arr = new char[h, h];
for (int row=0; row < h; row++)
{
for (int col = h-1; col >= 0; col--)
{
if (col >= h -1 - row)
arr[row, col] = '*';
else arr[row, col] = ' ';
}
}
for (int i = 0; i < h; i++)
{
for (int j = 0; j < h; j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
}
private static void paintDecreasingRightTriangle(int h)
{
var arr = new char[h, h];
for (int row = 0; row < h; row++)
{
for (int col = h - 1; col >= 0; col--)
{
if (col <= h - 1 - row)
arr[row, col] = '*';
else arr[row, col] = ' ';
}
}
for (int i = 0; i < h; i++)
{
for (int j = 0; j < h; j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
}
}