본문 바로가기
Baekjoon/단계별로 풀어보기

[단계04] while문 (3문제)

by 해적거북 2020. 12. 17.
728x90

www.acmicpc.net/step/2

 

● [문제번호 10952] A+B - 5

#include <stdio.h>

int main()
{
    int A, B;
    scanf("%d %d", &A, &B);
    
    while(A != 0 && B != 0)
    {
        printf("%d\n", A + B);
        scanf("%d %d", &A, &B);
    }

    return 0;
}

 

● [문제번호 10951] A+B - 4

#include <stdio.h>

int main()
{
    int A, B;
    
    while(scanf("%d %d", &A, &B) != EOF)
        printf("%d\n", A + B);

    return 0;
}

// 커맨드를 이용한 반복문 종료 (연구 필요)

 

● [문제번호 1110] 더하기 사이클

#include <stdio.h>

int main()
{
    int N, count = 0;
    scanf("%d", &N);
    
    int temp1 = N;
    do
    {
        count++;
        
        int temp2 = temp1;
        
        if(10 <= temp2)
            temp2 = ((temp2 / 10) + (temp2 % 10));
        
        temp1 = ((temp1 % 10) * 10 + (temp2 % 10));
        
    }while(N != temp1);

    printf("%d", count);
    
    return 0;
}
728x90

댓글