Most Probable SLC asked questions

1. Write a program to display all armstrong number from 1 to 2000 using FUNCTION...END FUNCTION.
DECLARE FUNCTION display ()
CLS
v = display
END

FUNCTION display
FOR i = 1 TO 2000
N = i
S = 0
WHILE N <> 0
R = N MOD 10
S = S + R ^ 3
N = N \ 10

WEND
IF S = i THEN
PRINT i,
END IF
NEXT i

END FUNCTION

2. Write a program to check given input number is armstrong or not using FUNCTION...END FUNCTION.

DECLARE FUNCTION armstrong$ (N)
CLS
INPUT "Enter a number"; N
PRINT armstrong$(N)
END

FUNCTION armstrong$ (N)
O = N
WHILE N <> 0
R = N MOD 10
S = S + R ^ 3
N = N \ 10

WEND
IF S = O THEN
armstrong$ = STR$(O) + " is armstrong number"
ELSE
armstrong$ = STR$(O) + " is not armstrong number"

END IF

END FUNCTION


Comments