Wednesday, November 20, 2013

Part I


WRITE a program to Display:


 1)
 J
 JA
 JAG
 JAGA
 JAGAT

ANS :

REM
CLS
S$=”JAGAT”
FOR I=1 TO LEN(S$)
PRINT LEFT$(S$, I)
NEXT I
END


2)T    
 AT
GAT
AGAT
JAGAT

ANS :

REM
CLS
S$=”JAGAT”
FOR I=1 TO LEN(S$)
PRINT RIGHT$(S$,I)
NEXT I
END


3)
JAGAT
JAGA
JAG
JA
J

Ans:

REM
CLS
S$=”JAGAT”
FOR I=LEN(S$) TO 1 STEP-1
PRINT RIGHT$(S$, I)
NEXT I
END


4)
JAGAT
AGAT
GAT
AT
T

Ans:
             
REM
CLS
S$=”JAGAT”
FOR I= LEN(S$) TO 1 STEP-1
PRINT RIGHT$(S$, I)
NEXT I
END


5)
J
A
G
A
T

Ans:

REM
CLS
S$=”JAGAT”
FOR I=1 TO LEN(S$)
PRINT MID$(S$, I, 1)
NEXT I
END


6)
T
A
G
A
J

Ans:

REM
CLS
S$=”JAGAT”
FOR I=LEN(S$) TO 1 STEP-1
PRINT MID$(S$, I, 1)
NEXT I
END


7)
JAGAT
AGA
G

Ans:

REM
CLS
S$=”JAGAT”
A=5
FOR I=1 TO 3
PRINT MID$(S$, I, A)
A=A-2
NEXT I
END




8)
G
AGA
JAGAT

Ans:

REM
CLS
S$=”JAGAT”
A=1
FOR I=3 TO 1 step-1
PRINT MID$(S$, I, A)
A=A+2
NEXT I
END



9)
*
**
***
****
*****

Ans:

REM
CLS
S$=”*****”
FOR I=1 TO LEN(S$)
PRINT LEFT$(S$, I)
NEXT I
END

10)
*****
****
***
**
*

Ans:

REM
CLS
S$=”*****”
FOR I=LEN(S$) TO 1 STEP-1
PRINT LEFT$(S$, 1)
NEXT I
END



 Part  II



Wap to enter any number and display.


1)Sum of digits.

Ans:

REM
CLS
S=0
INPUT ”Enter any number”; N
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT ”Sum of digits”; S
END

2)Sum of even digits.

Ans:

REM
CLS
S=0
INPUT ”Enter any 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”; S
END

3)Sum of odd digits.

Ans:

REM
CLS
S=0
INPUT ”Enter any 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”; 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”;  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”; 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”; S
END

7)Sum of square 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^2
N=N\10
WEND
PRINT “Sum of square of odd digits”; 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”; 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

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



Part  III


WAP to enter any number and display:


1)WAP to display reverse the given digits.

REM
CLS
S=0
INPUT “Enter a number”; N
WHILE N<>0
R=N MOD 10
S=S * 10 + R
N=N\10
WEND
PRINT “The reverse number is”; S
END


2) WAP to display product of entered digits.

REM
CLS
P=1
INPUT “Enter a number”; N
WHILE N<>0
R= N MOD 10
P= P *R
N= N\10
WEND
PRINT “The product of entered digits is”; P
END


3)WAP to display product of even digits.

REM
CLS
P=1
INPUT “Enter a number”; N
WHILE N<>0
R= N MOD 10
IF R MOD 2=0 THEN P= P*R
N=N\10
WEND
PRINT “The product of even digits is”; P
END

4)WAP to display product of odd digits.

REM
CLS
P=1
INPUT “Enter a number”; N
WHILE N<>0
R= N MOD 10
IF R MOD 2=1 THEN P= P*R
N=N\10
WEND
PRINT “The product of odd digits is”; P
END


5)WAP to count total number of entered digits.

REM
CLS
S=0
INPUT ”Enter a number”; N
WHILE N<>0
R= N MOD 10
S= S+1
N=N\10
WEND
PRINT “The total number of digits”; S
END


6)WAP to count total number of even digits.

REM
CLS
S=0
INPUT “Enter a number”; N
WHILE N<>0
R= N MOD 10
IF R MOD 2 = 0 THEN S = S+1
N= N\10
WEND
PRINT “The total number of even digits”; S
END


7)WAP to count total number of odd digits.

REM
CLS
S=0
INPUT “Enter a number”; N
WHILE N<>0
R= N MOD 10
IF R MOD 2 = 1 THEN S = S+1
N= N\10
WEND
PRINT “The total number of odd digits”; S
END


8)WAP to check whether the given number is Palindrome or not.

REM
CLS
S=0
INPUT ”Enter a number”; N
A=N
WHILE N<>0
R= N MOD 10
S= S * 10 + R
N= N\10
WEND
IF A=S THEN
PRINT “The given number is palindrome”
ELSE
PRINT ”The given number is not palindrome”
END IF
END


9)WAP to check whether the given number is Armstrong or not.

REM
CLS
S=0
INPUT “Enter any number”; N
A=N
WHILE N <>0
R= N MOD 10
S=S+R^3
N=N\10
WEND
IF A=S THEN
PRINT “The given number is Armstrong”
ELSE
PRINT “The given number is not Armstrong”
END IF
END


No comments:

Post a Comment