Wednesday, November 20, 2013

QBASIC Programmings

Part I
WAP to display:

1.      J
JA
JAG
JAGA
JAGAT
=>
REM
CLS
S$=”JAGAT”
FOR I = 1 TO LEN(S$)
PRINT LEFT$(S$, I)
NEXT I
END

2.      T
AT
GAT
AGAT
JAGAT
=>
REM
CLS
S$=”JAGAT”
FOR I =1 TO LEN(S$)
PRINT RIGHT$(S$, I)
NEXT I
END

3.      JAGAT
AGAT
GAT
AT
T
=>
REM
CLS
S$=”JAGAT”
FOR I = LEN (S$) TO  1 STEP -1
PRINT RIGHT$(S$, I)
NEXT I
END
 
4.      JAGAT
JAGA
JAG
JA
J
=>
REM
CLS
S$=”JAGAT”
FOR I = LEN(S$) TO 1 STEP -1
PRINT LEFT$(S$, I)
NEXT I
END

5.      J
A
G
A
T
=>
REM
CLS
S$=”JAGAT”
FOR I = 1 TO LEN(S$)
PRINT MID$(S$, I, 1)
NEXT I
END

6.      T
A
G
A
J
=>
REM
CLS
S$=”JAGAT”
FOR I = LEN (S$) TO 1 STEP -1
PRINT MID$(S$, I, 1)
NEXT I
END

7.      JAGAT
AGA
G
=>
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
=>
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.     *
**
***
****
*****
=>
REM
CLS
S$=”*****”
FOR I = 1 TO LEN(S$)
PRINT LEFT$(S$, I)
NEXT I
END

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

Part II
WAP to enter any number and display

1.      Sum of digits.
=>
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 is”; S
END

2.      Sum of even digits.
=>
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 is”; S
END

3.      Sum of odd digits.
=>
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 is”; S
END

4.      Sum of square of digits.
=>
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

5.      Sum of cube of digits.
=>
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  

6.      Sum of square 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+R^2
N=N\10
WEND
PRINT ”Sum of square of even digits is”; S
END

7.      Sum of square of odd digits.
=>
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

8.     Sum of cube 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+R^3
N=N\10
WEND
PRINT ”Sum of cube of even digits is”; S
END

9.     Sum of cube 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+R^3
N=N\10
WEND
PRINT ”Sum of cube of odd digits is”; S
END

10. Even digits.
=>
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

11.  Odd digits.
=>
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

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 is”; 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 is”; 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 is”; 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



3 comments: