Assignment for class IX (part ii)
WAP
to enter any number and display:
1.
Sum of digits.
Ans à
REM
CLS
S: 0
INPUT “ENTER A NUMBER”;N
WHILE N <> 0
R = N MOD 10
S = S + R
N = N \10
WEND
PRINT “SUM OF DIGITS IS” ; S
END
2. Sum of even digits.
Ans à
REM
CLS
S: 0
INPUT “ENTER A NUMBER”;N
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 IS ” ; S
END
3. Sum of odd digits.
Ans à
REM
CLS
S: 0
INPUT “ENTER A NUMBER”;N
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 IS” ; S
END
4. Sum of square of digits.
Ans à
REM
CLS
S=0
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R= N MOD 10
S = S+R^2
N= N\10
WEND
PRINT “SUM OF SQUARE OF DIGITS IS”;S
END
CLS
S=0
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R= N MOD 10
S = S+R^2
N= N\10
WEND
PRINT “SUM OF SQUARE OF DIGITS IS”;S
END
5. Sum of cube of digits.
Ans à
REM
CLS
S=0
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R=N MOD 10
S=S+R^3
N=N\10
WEND
PRINT “SUM OF CUBE OF DIGITS IS”; S
END
CLS
S=0
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R=N MOD 10
S=S+R^3
N=N\10
WEND
PRINT “SUM OF CUBE OF DIGITS IS”; S
END
6. Sum of square of even digits.
Ans à
REM
CLS
S=0
INPUT “ENTER A NUMBER”; N
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 IS”; S
END
CLS
S=0
INPUT “ENTER A NUMBER”; N
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 IS”; S
END
7. Sum of square of odd digits.
Ans à
REM
CLS
S=0
INPUT ”ENTER A NUMBER”; N
WHILE N<>0
R=NMOD 10
IF R MOD 2=1 THEN S=S+R^2
N=N\10
WEND
PRINT “SUM OF SQUARE OF ODD DIGITS IS”; S
END
CLS
S=0
INPUT ”ENTER A NUMBER”; N
WHILE N<>0
R=NMOD 10
IF R MOD 2=1 THEN S=S+R^2
N=N\10
WEND
PRINT “SUM OF SQUARE OF ODD DIGITS IS”; S
END
8. Sum of cube of even digits.
Ans à
REM
CLS
S=0
INPUT “ENTER A NUMBER”; N
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 IS”; S
END
CLS
S=0
INPUT “ENTER A NUMBER”; N
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 IS”; S
END
9. Sum of cube of odd digits.
Ans à
REM
CLS
S=0
INPUT “ENTER A NUMBER”; N
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
CLS
S=0
INPUT “ENTER A NUMBER”; N
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
10. Even digits.
Ans à
REM
CLS
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R=N MOD 10
IF R MOD 2=0 THEN PRINT R
N=N\10
WEND
END
CLS
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R=N MOD 10
IF R MOD 2=0 THEN PRINT R
N=N\10
WEND
END
11. Odd digits.
Ans à
REM
CLS
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R=N MOD 10
IF R MOD 2=1 THEN PRINT R
N=N\10
WEND
END
CLS
INPUT “ENTER A NUMBER”; N
WHILE N<>0
R=N MOD 10
IF R MOD 2=1 THEN PRINT R
N=N\10
WEND
END
Comments
Post a Comment