# theinfozones.com

## To check given number is armstrong or not. (Qbasic)

• What is Armstrong number?
• The number which is formed by the sum of cubes of its own digits is Armstrong number.
• Example: 153, 370, 371, 407, etc.
• 153 = 13 + 53 + 33
= 1 + 125 + 27
= 153
Qbasic Code
Using DO WHILE ..... LOOP
CLS
INPUT "Enter a number"; n
b = n
DO WHILE n <> 0
r = n MOD 10
a = a + r ^ 3
n = n \ 10
LOOP
IF a = b THEN
PRINT "It is armstrong number";
ELSE
PRINT "It is not armstrong number";
END IF
END

Using WHILE ... WEND
CLS
INPUT "ENTER ANY NUMBER"; N
A = N
S = 0
WHILE N <> 0
R = N MOD 10
S = S + R ^ 3
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS ARMSTRONG"
ELSE
PRINT A; "IS NOT ARMSTRONG"
END IF
END

Using SUB Procedure
DECLARE SUB ARM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL ARM(N)
END

SUB ARM (N)
A = N
S = 0
WHILE N <> 0
R = N MOD 10
S = S + R ^ 3
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS ARMSTRONG NUMBER"
ELSE
PRINT A; "IS NOT ARMSTRONG NUMBER"
END IF
END SUB

Using Function Procedure
DECLARE FUNCTION ARM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = N
AR = ARM(N)
IF A = AR THEN
PRINT A; "IS ARMSTRONG NUMBER"
ELSE
PRINT A; "IS NOT ARMSTRONG NUMBER"
END IF
END

FUNCTION ARM (N)
S = 0
WHILE N <> 0
R = N MOD 10
S = S + R ^ 3
N = N \ 10
WEND
ARM = S
END FUNCTION

#### Share : 