a

[알고리즘] 12221. 구구단2

박은성/ 2022. 3. 16. 16:27
반응형

 

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXpz3dravpQDFATi 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

아기 석환이는 최근 구구단을 배웠다. 그래서 1 이상 9 이하의 자연수 두개를 곱셈할 수 있으나, 10 이상의 자연수를 곱셈하는 방법은 모른다.
두 정수 A, B가 주어진다. 아기 석환이 두 정수를 곱셈할 수 있으면 곱을 출력하고, 아니면 -1을 출력하라.

풀이 방법)

2자리수인지 조건문

#include <stdio.h>
int main(void)
{
	int test_case;
	int T;
	int res = -1; //결과를 담을 res
    
	setbuf(stdout, NULL);
	scanf("%d", &T);
	
	for (test_case = 1; test_case <= T; ++test_case)
	{
		int a,b;
        scanf("%d %d", &a, &b);
        if(a > 9 || b > 9) {
            res = -1;
        	printf("#%d %d\n", test_case, res);
        }else{
            res = a*b;
       		printf("#%d %d\n", test_case, res);
        }
	}
	return 0;
}
반응형