PALINDROME AND ARMSTRONG PROGRAMS



120. WAP to input any number and check whether the given no. is palindrome or not.

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

USING SUB PROCEDURE

DECLARE SUB PALIN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PALIN (N)
END

SUB PALIN (N)
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
IF A = S THEN
PRINT A; "IS PALINDROME"
ELSE
PRINT A; "IS NOT PALINDROME"
END IF
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PALIN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
P = PALIN ((N))
IF P = N THEN
PRINT N; "IS PALINDROME"
ELSE
PRINT N; "IS NOT PALINDROME"
END IF
END

FUNCTION PALIN (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
PALIN = S
END FUNCTION
121. WAP to display first 20 palindrome numbers.

CLS
N = 1
CNT = 1
TOP:
A = N
S = 0
WHILE A < > 0
R = A MOD 10
S = S * 10 + R
A = A \ 10
WEND
IF N = S THEN
PRINT N,
CNT = CNT + 1
END IF
N = N + 1
IF CNT <= 20 THEN GOTO TOP
END

USING SUB PROCEDURE

DECLARE SUB PALIN ( )
CLS
CALL PALIN
END

SUB PALIN
N = 1
CNT = 1
TOP:
A = N
S = 0
WHILE A < > 0
R = A MOD 10
S = S * 10 + R
A = A \ 10
WEND
IF N = S THEN
PRINT N,
CNT = CNT + 1
END IF
N = N + 1
IF CNT <= 20 THEN GOTO TOP
END SUB

122.   WAP to display all palindrome numbers from 1 to 200.

CLS
N = 1
FOR I = 1 TO 200
A = N
S = 0
WHILE A < > 0
R = A MOD 10
S = S * 10 + R
A = A \ 10
WEND
IF N = S THEN PRINT N,
N = N + 1
NEXT I
END

USING SUB PROCEDURE

DECLARE SUB PALIN ( )
CLS
CALL PALIN
END

SUB PALIN
N = 1
FOR I = 1 TO 200
A = N
S = 0
WHILE A < > 0
R = A MOD 10
S = S * 10 + R
A = A \ 10
WEND
IF N = S THEN PRINT N,
N = N + 1
NEXT I
END SUB





123. WAP to input any number and check whether the given no. is Armstrong or not.

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



124. WAP to display first 5 Armstrong numbers.


CLS
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

USING SUB PROCEDURE

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


125.   WAP to display all Armstrong numbers from 1 to 500.

CLS
N = 1
FOR I = 1 TO 500
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,
N = N + 1
NEXT I
END

USING SUB PROCEDURE

DECLARE SUB ARM ( )
CLS
CALL ARM
END

SUB ARM
N = 1
FOR I = 1 TO 500
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,
N = N + 1
NEXT I
END SUB

Comments

Unknown said…
Veeeeeeeeeeeeeery veeeeeeeeeeeeeery veeeeeeeeeeeeeery nice one helped me a lot
Santos said…
what's the job of m=palind((n)) in palindromic number program????
Unknown said…
This comment has been removed by the author.
Unknown said…
sir/ma'am
i can't understand the palindrome program .
could you please help me?
Unknown said…
it cleared my doubt
Kismat said…
why are you using A=N and what is the value of A

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS