PL/SQL Program for Armstrong Number
Here you will learn pl/sql program for armstrong number using power function in pl/sql programming.
153 is an Armstrong number because: 13 + 53 + 33 = 153
PL/SQL Program for Armstrong Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | DECLARE num NUMBER := &Enter_Number; -- get user input number temp NUMBER := num; digit NUMBER; sum_of_pow NUMBER := 0; BEGIN -- Loop to calculate cubes of the digits WHILE temp_num > 0 LOOP digit := MOD(temp, 10); sum_of_pow := sum_of_pow + POWER(digit, 3); temp := FLOOR(temp / 10); END LOOP; -- If input number is equals to sum of cubes of its digits IF num = sum_of_pow THEN DBMS_OUTPUT.PUT_LINE('The number is an Armstrong number.'); ELSE DBMS_OUTPUT.PUT_LINE('The number is not an Armstrong number.'); END IF; END; / |
Output 1
Enter_Number 153
The number is an Armstrong number.
Output 2
Enter_Number 2563
The number is not an Armstrong number.
Check out our other PL/SQL programs examples