구구단 출력3

Console Programming/C# Console 2019. 9. 20. 05:20

2 x 1 =  2    3 x 1 =  3    4 x 1 =  4 

2 x 2 =  4

2 x 3 =  6

2 x 4 =  8

2 x 5 = 10

2 x 6 = 12

2 x 7 = 14

2 x 8 = 16

2 x 9 = 18

 

5 x 1 =  5    6 x 1 =  6

5 x 2 = 10

5 x 3 = 15

5 x 4 = 20

5 x 5 = 25

5 x 6 = 30

5 x 7 = 35

5 x 8 = 40

5 x 9 = 45

 

이런 식으로 3단씩 끊어서 출력되는 프로그램

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 2; i < 10; i++)
            {
                if (i < 5)
                {
                    for (int j = 1; j < 10; j++)
                    {
                        Console.Write(String.Format("{0,1} x {1,1} = {2,2}    ", i, i, (i * j)));
                    }
                    Console.WriteLine();
                }
                else if (i < 8)
                {
                    for (int j = 1; j < 10; j++)
                    {
                        Console.Write(String.Format("{0,1} x {1,1} = {2,2}    ", i, i, (i * j)));
                    }
                    Console.WriteLine();
                }
                else
                {
                    for (int j = 1; j < 10; j++)
                    {
                        Console.Write(String.Format("{0,1} x {1,1} = {2,2}    ", i, i, (i * j)));
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

첫번째 코드 실행결과

Console.Write안의 object를 넣을때 i, j 를 넣어야하는데 i, i를 넣었다.

: