구구단 출력3
Console Programming/C# Console 2019. 9. 20. 05:24
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int count = 0;
for (int k = 1; k < 4; k++)
{
if (k < 2)
{
for (int i = 1; i < 10; i++)
{
for (int j = 2; j < 5; j++)
{
Console.Write(String.Format("{0,1} x {1,1} = {2,2} ", j, i, (i * j)));
}
Console.WriteLine();
}
}
else if (k<3)
{
for (int i = 1; i < 10; i++)
{
for (int j = 5; j < 8; j++)
{
Console.Write(String.Format("{0,1} x {1,1} = {2,2} ", j, i, (i * j)));
}
Console.WriteLine();
}
}
else
{
for (int i = 1; i < 10; i++)
{
for (int j = 8; j < 10; j++)
{
Console.Write(String.Format("{0,1} x {1,1} = {2,2} ", j, i, (i * j)));
}
Console.WriteLine();
}
}
Console.WriteLine();
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
여러번의 시도 끝에 두 개의 for문 이외에도 줄바꿈을 시전하는 다른 for문이 필요한 것을 알아냈다.
for (int k = 1; k<4; k++) //총 세번의 줄바꿈을 한다.
if문을 써서 k의 값이 변화함에 따라 구구단의 단수를 2~4단 5~7단 8~9단으로 바꾸었다.

'Console Programming > C# Console' 카테고리의 다른 글
Console.ReadLine(); (0) | 2019.09.20 |
---|---|
Console.WriteLine Method (0) | 2019.09.20 |
구구단 출력3 (0) | 2019.09.20 |
구구단 출력2 (0) | 2019.09.20 |
구구단 출력 (0) | 2019.09.20 |