C#/수업내용

2020.04.07. 수업내용 - while 문 2 (구구단)

dev_sr 2020. 4. 7. 22:00

 

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
            //3. while-구구단
 
            //반복문에서 곱해질 카운트되는 변수를 정의한다.
            int gugudanCount = 0;
 
            while (true)
            {
                //단 값을 입력받는다
                Console.Write("출력하고 싶은 구구단의 단수를 입력하세요:  ");
                int dan = Convert.ToInt32(Console.ReadLine());
 
                //1~9까지 반복해서 곱해질 카운터를 증가시킨다
                while (true)
                {
                    gugudanCount++;
                    Console.WriteLine("{0} x {1} = {2}", dan, gugudanCount, dan * gugudanCount);
 
                    //카운트가 9이면 카운트를 초기화하고 빠져나와 다시 입력받는다
                    if (gugudanCount >= 9)
                    {
                        gugudanCount = 0;
                        break;
                    }
                }
                //단수가 -1이면 종료한다
                if(dan==-1)
                {
                    Console.WriteLine("구구단 프로그램을 종료합니다.");
                    break;
                }
 
            }
 
 

 

 

결과값