SUM OF [DIGITS, ODD DIGITS, EVEN DIGITS, SQUARE OF DIGITS, CUBE OF DIGITS, SQUARE OF EVEN, CUBE OF EVEN, SQUARE OF ODD, CUBE OF ODD]



101. WAP to input number and find sum of digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
S = 0
WHILE N < > 0
R = N MOD 10
S = S + R
N = N \ 10
WEND
PRINT "SUM OF DIGITS"; S
END

USING SUB PROCEDURE

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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUM (N)
PRINT "SUM OF DIGITS"; SU
END

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


102.   WAP to input number and find sum of odd digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMODD (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMODD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMODD (N)
PRINT "SUM OF ODD DIGITS"; SU
END

FUNCTION SUMODD (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R
N = N \ 10
WEND
SUMODD = S
END FUNCTION


103.   WAP to input number and find sum of even digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMEVEN (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMEVEN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMEVEN (N)
PRINT "SUM OF EVEN DIGITS"; SU
END

FUNCTION SUMEVEN (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R
N = N \ 10
WEND
SUMEVEN = S
END FUNCTION


104. WAP to input number and find sum square of digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMSQ (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMSQ (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMSQ (N)
PRINT "SUM OF SQUARE OF DIGITS"; SU
END

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


105.   WAP to input number and find sum of square of odd digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMODD (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMODD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMODD (N)
PRINT "SUM OF SQUARE OF ODD DIGITS"; SU
END

FUNCTION SUMODD (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R ^ 2
N = N \ 10
WEND
SUMODD = S
END FUNCTION


106.   WAP to input number and find sum of square of even digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMEVEN (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMEVEN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMEVEN (N)
PRINT "SUM OF SQUARE OF EVEN DIGITS"; SU
END

FUNCTION SUMEVEN (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R ^ 2
N = N \ 10
WEND
SUMEVEN = S
END FUNCTION



107. WAP to input number and find sum of cube of digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMCB (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMCB (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMCB (N)
PRINT "SUM OF CUBE OF DIGITS"; SU
END

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


108.   WAP to input number and find sum of cube of odd digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMODD (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMODD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMODD (N)
PRINT "SUM OF CUBE OF ODD DIGITS"; SU
END

FUNCTION SUMODD (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R ^ 3
N = N \ 10
WEND
SUMODD = S
END FUNCTION


109.   WAP to input number and find sum of cube of even digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; 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

USING SUB PROCEDURE

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

SUB SUMEVEN (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

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMEVEN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
SU = SUMEVEN (N)
PRINT "SUM OF CUBE OF EVEN DIGITS"; SU
END

FUNCTION SUMEVEN (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R ^ 3
N = N \ 10
WEND
SUMEVEN = S
END FUNCTION

Comments

Unknown said…
i need solution of 2 4 8 14 22 32...... 10th term series solution
Unknown said…
This comment has been removed by the author.
Unknown said…
This comment has been removed by the author.
Bibash Pokhrel said…
Write a qbasic program that asks to input any five numbers and displays sum of them.
Unknown said…
DIM x, num, sum AS INTEGER
x = 0
num = 0
FOR x = 1 TO 5
INPUT "enter a number"; num
sum = sum + num
NEXT x
PRINT "Sum:"; sum
END
Aayush Regmi said…
Thanks alot today is SEE exam of computer

Unknown said…
Your Affiliate Money Making Machine is ready -

Plus, earning money online using it is as simple as 1-2-3!

Here are the steps to make it work...

STEP 1. Tell the system what affiliate products you want to promote
STEP 2. Add some PUSH button traffic (it ONLY takes 2 minutes)
STEP 3. See how the system grow your list and sell your affiliate products all by itself!

So, do you want to start making profits??

Click here to activate the system
Unknown said…
Qbasic program to input any multi digit number and display both the sum of odd digits and even digits.
Raj-yesh Mandal said…
To read ten numbers using single dimension and find the sum of odd and even numbers separately by using function....end function

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

PALINDROME AND ARMSTRONG PROGRAMS