'전체 글'에 해당되는 글 276건

  1. 2019.09.20 구구단 출력3
  2. 2019.09.20 구구단 출력2
  3. 2019.09.20 구구단 출력

구구단 출력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를 넣었다.

:

구구단 출력2

Console Programming/C# Console 2019. 9. 20. 04:31

2 x 1 =  2    3 x 1 =  3    4 x 1 =  4    5 x 1 =  5    6 x 1 =  6    7 x 1 =  7    8 x 1 =   8    9 x 1 =  9

2 x 2 =  4    3 x 2 =  6    4 x 2 =  8    5 x 2 = 10    6 x 2 = 10 ...

 

이런식으로 출력되는 프로그램

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 = 1; i < 10; i++)
            {
                for (int j = 2; j < 10; j++)
                {
                    Console.Write(String.Format("{0,1} x {1,1} = {2,2}    ", j, i, (j*i)));
                }
                Console.WriteLine();
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

String.Format(string format, object arg0, object arg1, object arg2) 를 사용함

 

     

:

구구단 출력

Console Programming/C# Console 2019. 9. 20. 04:22

2 x 1 = 2

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

 

3 x 1 = 3

3 x 2 = 6

.

.

.

을 출력하는 프로그램

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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++)
            {
                for (int j = 1; j < 10; j++)
                {
                    Console.WriteLine($"{i} x {j} = {i * j}");
                }
                Console.WriteLine();
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 

 

 

: