Wednesday, October 16, 2019

71. Qbasic program to display first 5 Armstrong numbers.


71.      Write a sub program to display first 5 Armstrong numbers.

DECLARE SUB ARM ( )
CLS
CALL ARM
END
SUB ARM
N = 1 : CNT = 1
TOP:
A = N
S = 0
WHILE A < > 0
R = A MOD 10
S = S + R ^ 3
A = A \ 10
WEND
IF N = S THEN
PRINT N,
CNT = CNT + 1
END IF
N = N + 1
IF CNT <= 5 THEN GOTO TOP
END SUB

2 comments: