Operation on Digits with SUB and FUNCTION Procedure
1. WAP to find the sum of digits.
=> DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S + R
N = N \ 10
WEND
PRINT "SUM OF DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S+R
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
2. WAP TO FIND SUM OF SQUARE OF DIGITS.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S + R^2
N = N \ 10
WEND
PRINT "SUM OF SQUARE OF DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF SQUARE OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S+R ^ 2
N = N \10
WEND
SUM = S
END FUNCTION
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S + R ^ 3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF CUBE OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S+R ^ 3
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
4. WAP TO REVERSE THE DIGITS,
=>DECLARE SUB REV(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL REV(N)
END
SUB REV(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S*10 + R
N = N \ 10
WEND
PRINT "REVERSED NUMBER = "; S
END SUB
=>DECLARE FUNCTION REV(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF DIGITS = "; REV(N)
END
FUNCTION REV(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S*10+R
N = N \10
WEND
REV= S
END FUNCTION
INPUT "ENTER ANY NUMBER";N
CALL PAL(N)
END
SUB PAL(N)
A = N
S = 0
WHILE N<>0
R = N MOD 10
S = S*10 + R
N = N \ 10
WEND
IF S = A THEN PRINT "THE NUMBER IS PALINDROME"
IF S<>A THEN PRINT "THE NUMBER IS NOT PALINDROME"
END SUB
=>DECLARE FUNCTION PAL(N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = N
IF A = PAL(N) THEN PRINT "THE NUMBER IS PALINDROME"
IF A <> PAL(N) THEN PRINT "THE NUMBER IS NOT PALINDROME"
END
FUNCTION PAL(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S*10+R
N = N \10
WEND
PAL= S
END FUNCTION
_________________________________________________________________________________
6. WAP TO CHECK WHETHER THE NUMBER IS ARMSTRONG OR NOT.
=>DECLARE SUB ARM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL ARM(N)
END
SUB ARM(N)
S = 0
A = N
WHILE N<>0
R = N MOD 10
S = S + R^3
N = N \ 10
WEND
IF A = S THEN PRINT "THE NUMBER IS ARMSTRONG"
IF A <> S THEN PRINT "THE NUMBER IS NOT ARMSTRONG"
END SUB
=>DECLARE FUNCTION ARM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = N
IF A = ARM(N) THEN PRINT "THE NUMBER IS ARMSTRONG"
IF A <> ARM(N) THEN PRINT "THE NUMBER IS NOT ARMSTRONG"
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
_________________________________________________________________________________
7. WAP TO FIND THE SUM OF EVEN DIGITS ONLY.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R
N = N \ 10
WEND
PRINT "SUM OF EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF EVEN DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+R
N = N \10
WEND
SUM = S
END FUNCTION
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R
N = N \ 10
WEND
PRINT "SUM OF ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF ODD DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+R
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
9. WAP TO FIND SUM OF SQUARE OF EVEN DIGITS ONLY.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R^2
N = N \ 10
WEND
PRINT "SUM OF SQUARE OF EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF SQUARE OF EVEN DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+R^2
N = N \10
WEND
SUM = S
END FUNCTION
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R^2
N = N \ 10
WEND
PRINT "SUM OF SQUARE OF ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF SQUARE OF ODD DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+R^2
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
11. WAP TO FIND CUBE OF EVEN DIGITS.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R^3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF CUBE OF EVEN DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+R^3
N = N \10
WEND
SUM = S
END FUNCTION
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R^3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF CUBE OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+R^3
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
13. WAP TO COUNT TOTAL DIGITS.
=>DECLARE SUB TOT(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL TOT(N)
END
SUB TOT(N)
S = 0
WHILE N<>0
S = S + 1
N = N \ 10
WEND
PRINT "TOTAL DIGITS = "; S
END SUB
=>DECLARE FUNCTION TOT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL DIGITS = "; TOT(N)
END
FUNCTION TOT(N)
S = 0
WHILE N<>0
S= S+1
N = N \10
WEND
TOT= S
END FUNCTION
_________________________________________________________________________________
14. WAP TO COUNT TOTAL EVEN DIGITS.
=>DECLARE SUB TOT(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL TOT(N)
END
SUB TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + 1
N = N \ 10
WEND
PRINT "TOTAL EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION TOT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL EVEN DIGITS = "; TOT(N)
END
FUNCTION TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+1
N = N \10
WEND
TOT= S
END FUNCTION
_________________________________________________________________________________
15. WAP TO COUNT TOTAL ODD DIGITS.
=>DECLARE SUB TOT(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL TOT(N)
END
SUB TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + 1
N = N \ 10
WEND
PRINT "TOTAL ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION TOT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL ODD DIGITS = "; TOT(N)
END
FUNCTION TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+1
N = N \10
WEND
TOT= S
END FUNCTION
_________________________________________________________________________________
=> DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S + R
N = N \ 10
WEND
PRINT "SUM OF DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S+R
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
2. WAP TO FIND SUM OF SQUARE OF DIGITS.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S + R^2
N = N \ 10
WEND
PRINT "SUM OF SQUARE OF DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF SQUARE OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S+R ^ 2
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
3. WAP TO FIND SUM OF CUBE OF DIGITS.
=>DECLARE SUB SUM(N)
CLSINPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S + R ^ 3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF CUBE OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S+R ^ 3
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
4. WAP TO REVERSE THE DIGITS,
=>DECLARE SUB REV(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL REV(N)
END
SUB REV(N)
S = 0
WHILE N<>0
R = N MOD 10
S = S*10 + R
N = N \ 10
WEND
PRINT "REVERSED NUMBER = "; S
END SUB
=>DECLARE FUNCTION REV(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF DIGITS = "; REV(N)
END
FUNCTION REV(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S*10+R
N = N \10
WEND
REV= S
END FUNCTION
_________________________________________________________________________________
5. WAP TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME OR NOT.
=>DECLARE SUB PAL(N)
CLSINPUT "ENTER ANY NUMBER";N
CALL PAL(N)
END
SUB PAL(N)
A = N
S = 0
WHILE N<>0
R = N MOD 10
S = S*10 + R
N = N \ 10
WEND
IF S = A THEN PRINT "THE NUMBER IS PALINDROME"
IF S<>A THEN PRINT "THE NUMBER IS NOT PALINDROME"
END SUB
=>DECLARE FUNCTION PAL(N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = N
IF A = PAL(N) THEN PRINT "THE NUMBER IS PALINDROME"
IF A <> PAL(N) THEN PRINT "THE NUMBER IS NOT PALINDROME"
END
FUNCTION PAL(N)
S = 0
WHILE N<>0
R = N MOD 10
S= S*10+R
N = N \10
WEND
PAL= S
END FUNCTION
_________________________________________________________________________________
6. WAP TO CHECK WHETHER THE NUMBER IS ARMSTRONG OR NOT.
=>DECLARE SUB ARM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL ARM(N)
END
SUB ARM(N)
S = 0
A = N
WHILE N<>0
R = N MOD 10
S = S + R^3
N = N \ 10
WEND
IF A = S THEN PRINT "THE NUMBER IS ARMSTRONG"
IF A <> S THEN PRINT "THE NUMBER IS NOT ARMSTRONG"
END SUB
=>DECLARE FUNCTION ARM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
A = N
IF A = ARM(N) THEN PRINT "THE NUMBER IS ARMSTRONG"
IF A <> ARM(N) THEN PRINT "THE NUMBER IS NOT ARMSTRONG"
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
_________________________________________________________________________________
7. WAP TO FIND THE SUM OF EVEN DIGITS ONLY.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R
N = N \ 10
WEND
PRINT "SUM OF EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF EVEN DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+R
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
8. WAP TO FIND SUM OF ODD DIGITS ONLY.
=>DECLARE SUB SUM(N)
CLSINPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R
N = N \ 10
WEND
PRINT "SUM OF ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF ODD DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+R
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
9. WAP TO FIND SUM OF SQUARE OF EVEN DIGITS ONLY.
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R^2
N = N \ 10
WEND
PRINT "SUM OF SQUARE OF EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF SQUARE OF EVEN DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+R^2
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
10. WAP TO FIND SUM OF SQUARE OF ODD DIGITS.
=>DECLARE SUB SUM(N)
CLSINPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R^2
N = N \ 10
WEND
PRINT "SUM OF SQUARE OF ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF SQUARE OF ODD DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+R^2
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
=>DECLARE SUB SUM(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R^3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF CUBE OF EVEN DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+R^3
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
12. WAP TO FIND SUM OF CUBE OF ODD DIGITS.
=>DECLARE SUB SUM(N)
CLSINPUT "ENTER ANY NUMBER";N
CALL SUM(N)
END
SUB SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R^3
N = N \ 10
WEND
PRINT "SUM OF CUBE OF ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION SUM(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SUM OF CUBE OF DIGITS = "; SUM(N)
END
FUNCTION SUM(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+R^3
N = N \10
WEND
SUM = S
END FUNCTION
_________________________________________________________________________________
=>DECLARE SUB TOT(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL TOT(N)
END
SUB TOT(N)
S = 0
WHILE N<>0
S = S + 1
N = N \ 10
WEND
PRINT "TOTAL DIGITS = "; S
END SUB
=>DECLARE FUNCTION TOT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL DIGITS = "; TOT(N)
END
FUNCTION TOT(N)
S = 0
WHILE N<>0
S= S+1
N = N \10
WEND
TOT= S
END FUNCTION
_________________________________________________________________________________
=>DECLARE SUB TOT(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL TOT(N)
END
SUB TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + 1
N = N \ 10
WEND
PRINT "TOTAL EVEN DIGITS = "; S
END SUB
=>DECLARE FUNCTION TOT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL EVEN DIGITS = "; TOT(N)
END
FUNCTION TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S= S+1
N = N \10
WEND
TOT= S
END FUNCTION
_________________________________________________________________________________
=>DECLARE SUB TOT(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL TOT(N)
END
SUB TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + 1
N = N \ 10
WEND
PRINT "TOTAL ODD DIGITS = "; S
END SUB
=>DECLARE FUNCTION TOT(N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL ODD DIGITS = "; TOT(N)
END
FUNCTION TOT(N)
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S= S+1
N = N \10
WEND
TOT= S
END FUNCTION
_________________________________________________________________________________
_________________________________________________________________________________
Comments
Post a Comment