Qbasic Programs 1
Qbasic Programs 1
Qbasic Programs 1
SUB A (N)
S=N
WHILE N <> 0
B = N MOD 10
R = R * 10 + B
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT IT IS PALINDROME
ELSE
PRINT IT IS NOT PALINDROME
END IF
END SUB
Program to check a given string is palindrome or not in qbasic
CLS
INPUT ENTER A STRING; S$
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
IF S$ = REV$ THEN
PRINT THE GIVEN STRING IS PALINDROME
ELSE
PRINT IT IS NOT PALINDROME
END IF
Using declare sub
DECLARE SUB A(S$)
CLS
INPUT ENTER A STRING; S$
CALL A(S$)
END
SUB A(S$)
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
IF S$ = REV$ THEN
PRINT THE GIVEN STRING IS PALINDROME
ELSE
PRINT IT IS NOT PALINDROME
END IF
END SUB
WEND
PRINT R
END
Using declare sub procedure
DECLARE SUB A(N)
CLS
INPUT ENTER A NUMBER; N
CALL A(N)
END
SUB A(N)
WHILE N <> 0
B = N MOD 10
R = R * 10 + B
N = FIX(N / 10)
WEND
PRINT R
END SUB
Using declare function procedure
DECLARE FUNCTION A(N)
CLS
INPUT ENTER A NUMBER; N
PRINT A(N)
END
FUNCTION A(N)
WHILE N <> 0
B = N MOD 10
R = R * 10 + B
N = FIX(N / 10)
WEND
A=R
END FUNCTION
Program to convert decimal to hexadecimal in qbasic
THIS PROGRAM CONVERTS DECIMAL NUMBER INTO HEXADECIMAL
CLS
INPUT ENTER A DECIMAL VALUE; N
WHILE N <> 0
K = N MOD 16
IF K = 10 THEN
B$ = A
ELSEIF K = 11 THEN
B$ = B
ELSEIF K = 12 THEN
B$ = C
ELSEIF K = 13 THEN
B$ = D
ELSEIF K = 14 THEN
B$ = E
ELSEIF K = 15 THEN
B$ = F
ELSE
B$ = STR$(K)
END IF
H$ = B$ + H$
N = FIX(N / 16)
WEND
PRINT HEXADECIMAL VALUE IS ; H$
END
Using declare function procedure
THIS PROGRAM CONVERTS DECIMAL NUMBER INTO HEXADECIMAL
DECLARE FUNCTION Z$ (N)
CLS
INPUT ENTER A DECIMAL VALUE; N
PRINT HEXADECIMAL VALUE IS ; Z$(N)
END
FUNCTION Z$ (N)
WHILE N <> 0
K = N MOD 16
IF K = 10 THEN
B$ = A
ELSEIF K = 11 THEN
B$ = B
ELSEIF K = 12 THEN
B$ = C
ELSEIF K = 13 THEN
B$ = D
ELSEIF K = 14 THEN
B$ = E
ELSEIF K = 15 THEN
B$ = F
ELSE
B$ = STR$(K)
END IF
H$ = B$ + H$
N = FIX(N / 16)
WEND
Z$ = H$
END FUNCTION
Using declare sub procedure
THIS PROGRAM CONVERTS DECIMAL NUMBER INTO HEXADECIMAL
DECLARE SUB Z (N)
CLS
INPUT ENTER A DECIMAL VALUE; N
CALL Z(N)
END
SUB Z (N)
WHILE N <> 0
K = N MOD 16
IF K = 10 THEN
B$ = A
ELSEIF K = 11 THEN
B$ = B
ELSEIF K = 12 THEN
B$ = C
ELSEIF K = 13 THEN
B$ = D
ELSEIF K = 14 THEN
B$ = E
ELSEIF K = 15 THEN
B$ = F
ELSE
B$ = STR$(K)
END IF
H$ = B$ + H$
N = FIX(N / 16)
WEND
PRINT HEXADECIMAL VALUE IS ; H$
END SUB
Program to convert decimal to octal in qbasic
THIS PROGRAM CONVERTS DECIMAL NUMBER TO Octal
CLS
INPUT ENTER A NUMBER; N
WHILE N <> 0
A = N MOD 8
B$ = STR$(A)
N = FIX(N /
C$ = B$ + C$
WEND
PRINT QUAINARY EQUIVALENT IS; C$
END
Using declare sub procedure
THIS PROGRAM CONVERTS DECIMAL NUMBER TO Octal
DECLARE SUB O(N)
CLS
INPUT ENTER A NUMBER; N
CALL O(N)
END
SUB O(N)
WHILE N <> 0
A = N MOD 8
B$ = STR$(A)
N = FIX(N /
C$ = B$ + C$
WEND
PRINT QUAINARY EQUIVALENT IS; C$
END SUB
Using declare function procedure
THIS PROGRAM CONVERTS DECIMAL NUMBER TO Octal
DECLARE FUNCTION O$(N)
CLS
INPUT ENTER A NUMBER; N
PRINT QUAINARY EQUIVALENT IS; O$(N)
END
FUNCTION O$(N)
WHILE N <> 0
A = N MOD 8
B$ = STR$(A)
N = FIX(N /
C$ = B$ + C$
WEND
O$=C$
END FUNCTION
Program to reverse a given string in qbasic
CLS
INPUT ENTER A STRING; S$
C=VAL(A$)
IF A$=A THEN C=10
IF A$=B THEN C=11
IF A$=C THEN C=12
IF A$=D THEN C=13
IF A$=E THEN C=14
IF A$=F THEN C=15
H=H+C*16^P
P=P+1
NEXT I
PRINT DECIMAL VALUE IS;H
END SUB
Program to convert decimal to binary in qbasic
THIS PROGRAM CONVERTS DECIMAL NUMBER TO BINARY
CLS
INPUT ENTER A NUMBER; N
WHILE N <> 0
A = N MOD 2
B$ = STR$(A)
N = FIX(N / 2)
C$ = B$ + C$
WEND
PRINT BINARY EQUIVALENT IS; C$
END
Using declare sub procedure
THIS PROGRAM CONVERTS DECIMAL NUMBER TO BINARY
DECLARE SUB A (N)
CLS
INPUT ENTER A NUMBER; N
CALL A(N)
END
SUB A (N)
WHILE N <> 0
E = N MOD 2
B$ = STR$(E)
N = FIX(N / 2)
C$ = B$ + C$
WEND
PRINT BINARY EQUIVALENT IS; C$
END SUB
P=P+1
NEXT I
PRINT DECIMAL VALUE IS ; M
END SUB
Using declare function procedure
THIS PROGRAM CONVERTS BINARY NUMBER TO DECIMAL
DECLARE FUNCTION Z (B$)
CLS
INPUT ENTER A BINARY NUMBER; B$
PRINT DECIMAL VALUE IS ; Z(B$)
END
FUNCTION Z (B$)
FOR I = LEN(B$) TO 1 STEP -1
A$ = MID$(B$, I, 1)
C = VAL(A$)
M=M+C*2^P
P=P+1
NEXT I
Z=M
END FUNCTION
Program to convert Octal to Decimal in Qbasic
THIS PROGRAM CONVERTS OCTAL TO DECIMAL
CLS
INPUT ENTER A OCTAL VALUE; B$
FOR I = LEN(B$) TO 1 STEP -1
A$ = MID$(B$, I, 1)
C = VAL(A$)
D=D+C*8^P
P=P+1
NEXT I
PRINT DECIMAL VALUE IS; D
END
Using declare function procedure
THIS PROGRAM CONVERTS OCTAL TO DECIMAL
DECLARE FUNCTION Z (B$)
CLS
INPUT ENTER A OCTAL VALUE; B$
PRINT DECIMAL VALUE IS; Z(B$)
END
FUNCTION Z (B$)
FOR I = LEN(B$) TO 1 STEP -1
A$ = MID$(B$, I, 1)
C = VAL(A$)
D=D+C*8^P
P=P+1
NEXT I
Z=D
END FUNCTION
Using declare sub procedure
THIS PROGRAM CONVERTS OCTAL TO DECIMAL
DECLARE SUB Z(B$)
CLS
INPUT ENTER A OCTAL VALUE; B$
CALL Z(B$)
END
SUB Z(B$)
FOR I = LEN(B$) TO 1 STEP -1
A$ = MID$(B$, I, 1)
C = VAL(A$)
D=D+C*8^P
P=P+1
NEXT I
PRINT DECIMAL VALUE IS; D
END SUB
Program to find the product of the digits of the given number in Qbasic
CLS
R=1
INPUT ENTER A NUMBER;N
WHILE N<>0
A = N MOD 10
R=R*A
N = FIX ( N / 10 )
WEND
PRINT PRODUCT OF DIGITS IS;R
END
Using declare sub procedure
DECLARE SUB C(N)
CLS