728x90
반응형
SMALL
12. 최소 공배수
-- 예제122. 16과 24의 최소 공배수는?
with num_d as ( select 16 num1, 24 num2
from dual )
select num1, max(level), num2, max(level), max(level)
from num_d
where mod(num1, level) = 0 and mod(num2, level) = 0
connect by level <= num2 ;
with num_d as ( select 16 num1, 24 num2
from dual )
select num1/max(level), num2/max(level), max(level)
from num_d
where mod(num1, level) = 0 and mod(num2, level) = 0
connect by level <= num2 ;
with num_d as ( select 16 num1, 24 num2
from dual )
select num1, num2, (num1/max(level) ) * (num2/max(level) )*max(level) as "최소 공배수"
from num_d
where mod(num1, level) = 0 and mod(num2, level) = 0
connect by level <= num2 ;
-- 문제1. 16, 24, 56의 최소 공배수를 출력하세요.
accept p_n1 prompt ' 첫번째 숫자를 입력하세요.' ;
accept p_n2 prompt ' 두번째 숫자를 입력하세요.' ;
accept p_n3 prompt ' 세번째 숫자를 입력하세요.' ;
with num_d as ( select &p_n1 as NUM1, &p_n2 as NUM2, &p_n3 as NUM3
from dual )
select NUM1, NUM2, NUM3, ( (NUM1/max(level)) * (NUM2/max(level))*(NUM3/max(level)) *max(level) ) as "최소 공배수"
from num_d
where mod(NUM1, level) = 0 and mod(NUM2, level) = 0 and mod(NUM3, level) = 0
connect by level <= NUM3 ;
728x90
반응형
LIST
'SQL 기초 실무 > SQL 알고리즘 문제' 카테고리의 다른 글
23.09.29. SQL Developer 알고리즘 문제 ⑭ (1) | 2023.10.05 |
---|---|
23.09.29. SQL Developer 알고리즘 문제 ⑬ (0) | 2023.10.05 |
23.09.29. SQL Developer 알고리즘 문제 ⑪ (0) | 2023.10.04 |
23.09.29. SQL Developer 알고리즘 문제 ⑩ (0) | 2023.10.04 |
23.09.29. SQL Developer 알고리즘 문제 ⑨ (0) | 2023.10.04 |