create or replace FUNCTION gcd(num1 IN out NUMBER, num2 IN out NUMBER) return NUMBER
Is
t NUMBER:=1;
BEGIN
while (mod(num2, num1)!=0)
loop
t := mod(num2, num1);
num2 := num1;
num1 := t;
end loop;
return num1;
end;
/
DECLARE
num1 NUMBER := 56; -- First number
num2 NUMBER := 98; -- Second number
gcd_result NUMBER; -- Variable to store the result
BEGIN
gcd_result := gcd(num1, num2);
-- Output the result
DBMS_OUTPUT.PUT_LINE('The GCD of ' || num1 || ' and ' || num2 || ' is ' || gcd_result);
END;
/
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter