백준문제풀이 3단계 반복문11 10952번 A + B - 5 (C#)

2024. 5. 4. 20:00백준 문제풀이/3단계 반복문

11번 문제

 

A + B를 출력하는데

A와B가 모두 0이면 종료 하는 문제

 

using System;
class BackJoon
{
    static void Main(string[] args)
    {
        bool isZero = true;
        while (isZero)
        {
            string[] Num = Console.ReadLine().Split();
            int A = int.Parse(Num[0]);
            int B = int.Parse(Num[1]);
            if (A == 0 && B == 0)
                isZero = false;
            else
                Console.WriteLine(A + B);
        }
    }
}

 

이번엔 for이 아닌 While을 써봤다.

isZero라는 bool형 변수를 두고 while을 제어해주었다.

break를 써서 종료시켜도 된다.

 

조건문을 사용해 둘다 0이면 종료

아니면 A+B를 출력.