Solution of important Questions

Qbasic program to check entered letter is capital or small (uppercase or lowercase)
REM PROGRAM TO CHECK ENTERED NUMBER IS UPPERCASE OR LOWERCASE
CLS
INPUT “Enter a letter”;A$
U$=UCASE$(A$)
IF U$=A$ THEN
PRINT “It is capital letter”
ELSE
PRINT “It is small letter”
ENDIF
END
USING DECLARE FUNCTION PROCEDURE
DECLARE FUNCTION UC$ (A$)
CLS
INPUT “Enter a letter”; A$
PRINT UC$(A$)
END
FUNCTION UC$ (A$)
CH$ = UCASE$(A$)
IF A$ = CH$ THEN
UC$ = “It is capital letter”
ELSE
UC$ = “It is small letter”
END IF
END FUNCTION
USING DECLARE SUB PROCEDURE

DECLARE SUB UC(A$)
CLS
INPUT “Enter a letter”; A$
CALL UC(A$)
END
SUB UC(A$)
CH$ = UCASE$(A$)
IF A$ = CH$ THEN
PRINT “It is capital letter”
ELSE
PRINT “It is small letter”
END IF
END SUB
Program to check a given number is palindrome or not in qbasic
CLS
INPUT “ENTER A NUMBER”; N
S = N
WHILE N <> 0
A = N MOD 10
R = R * 10 + A
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS PALINDROME”
ELSE
PRINT “IT IS NOT PALINDROME”
END IF

Using Declare Sub Procedure

DECLARE SUB A (N)
CLS
INPUT “ENTER A NUMBER”; N
CALL A(N)
END
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
Program to check given number is armstrong or not in qbasic
CLS
INPUT “ENTER A NUMBER”; N
S = N
WHILE N <> 0
A = N MOD 10
R = R + A ^ 3
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS ARMSTRONG”
ELSE
PRINT “IT IS NOT ARMSTRONG”
END IF
Using declare sub procedure
DECLARE SUB A(N)
CLS
INPUT “ENTER A NUMBER”; N
CALL A(N)
END
SUB A(N)
S=N
WHILE N <> 0
B = N MOD 10
R = R + B ^ 3
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS ARMSTRONG”
ELSE
PRINT “IT IS NOT ARMSTRONG”
END IF
END SUB
Program to reverse a given number in qbasic
CLS
INPUT “ENTER A NUMBER”; N
WHILE N <> 0
A = N MOD 10
R = R * 10 + A
N = FIX(N / 10)
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 / 8)
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 / 8)
C$ = B$ + C$
WEND
O$=C$
END FUNCTION
Program to reverse a given string 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
PRINT REV$
END
Using declare sub procedure
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
PRINT REV$
END SUB
Using declare function procedure
DECLARE FUNCTION A$ (S$)
CLS
INPUT “ENTER A STRING”; S$
PRINT A$(S$)
END
FUNCTION A$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
A$ = REV$
END FUNCTION
Program to converts Hexadecimal to Decimal in Qbasic
‘THIS PROGRAM CONVERTS HEXADECIMAL TO DECIMAL
CLS
INPUT “ENTER HEXADECIMAL VALUE”;B$
FOR I=LEN(B$) TO 1 STEP -1
A$=MID$(B$,I,1)
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
Using declare function procedure
‘THIS PROGRAM CONVERTS HEXADECIMAL TO DECIMAL
DECLARE FUNCTION Z(B$)
CLS
INPUT “ENTER HEXADECIMAL 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$)
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
Z=H
END FUNCTION
Using declare sub procedure
‘THIS PROGRAM CONVERTS HEXADECIMAL TO DECIMAL
DECLARE SUB Z(B$)
CLS
INPUT “ENTER HEXADECIMAL 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$)
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
Using declare function procedure
‘THIS PROGRAM CONVERTS DECIMAL NUMBER TO BINARY
DECLARE FUNCTION A$ (N)
CLS
INPUT “ENTER A NUMBER”; N
PRINT “BINARY EQUIVALENT IS”; A$(N)
END
FUNCTION A$ (N)
WHILE N <> 0
E = N MOD 2
B$ = STR$(E)
N = FIX(N / 2)
C$ = B$ + C$
WEND
A$=C$
END FUNCTION
Program to convert Binary to Decimal in qbasic
‘THIS PROGRAM CONVERTS BINARY NUMBER TO DECIMAL
CLS
INPUT “ENTER A BINARY NUMBER”; 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
PRINT “DECIMAL VALUE IS “; M
END
Using declare sub procedure
‘THIS PROGRAM CONVERTS BINARY NUMBER TO DECIMAL
DECLARE SUB Z(B$)
CLS
INPUT “ENTER A BINARY NUMBER”; B$
CALL Z(B$)
END
SUB 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
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
INPUT “ENTER A NUMBER”;N
CALL C(N)
END
SUB C(N)
R = 1
WHILE N<>0
A = N MOD 10
R = R * A
N = FIX ( N / 10 )
WEND
PRINT “PRODUCT OF DIGITS IS”;R
END SUB
Using declare function procedure
DECLARE FUNCTION C(N)
CLS
INPUT “ENTER A NUMBER”;N
PRINT “PRODUCT OF DIGITS IS”;C(N)
END
FUNCTION C(N)
R = 1
WHILE N<>0
A = N MOD 10
R = R * A
N = FIX ( N / 10 )
WEND
C = R
END FUNCTION
Program to find the sum of the digits of the given number in Qbasic
CLS
INPUT “ENTER A NUMBER”;N
WHILE N<>0
A = N MOD 10
R = R + A
N = FIX ( N / 10 )
WEND
PRINT “SUM OF DIGITS IS”;R
END
Using declare function procedure
DECLARE FUNCTION C(N)
CLS
INPUT “ENTER A NUMBER”;N
PRINT “SUM OF DIGITS IS”;C(N)
END
FUNCTION C(N)
WHILE N<>0
A = N MOD 10
R = R + A
N = FIX ( N / 10 )
WEND
C = R
END FUNCTION
Using declare sub procedure
DECLARE SUB C(N)
CLS
INPUT “ENTER A NUMBER”;N
CALL C(N)
END
SUB C(N)
WHILE N<>0
A = N MOD 10
R = R + A
N = FIX ( N / 10 )
WEND
PRINT “SUM OF DIGITS IS”;R
END SUB
Program to print fibonacci series in Qbasic
Write a program in Qbasic to print the fibonacci series up to tenth term. Using loops-FOR…NEXT & WHILE…WEND Fibonacci series is the series in which the next number is obtained by the sum of two number just front of it. The first two numbers are explained by the user.It can be obtained up to any term.Here, I am only doing of tenth term.You can change the number of output to any term just by changing the looping number.Here is example of a fibonacci series. suppose you entered the first two numbers-1 & 2 and upto the tenth term then your output will be as:
1,2,3,5,8,13,21,34,55,89
Here in the begining 1 & 2 are the entered numbers.3 is the product of 1 & 2 as the definition of fibonacci series given in first.like wise 5 is the sum of 2 & 3 and 8 is the sum of 3 & 5 and so on.

Using FOR…NEXT
CLS
A = 1
B = 2
PRINT A
PRINT B
FOR I = 1 TO 10
C = A + B
PRINT C
A = B
B = C
NEXT I
END
Using WHILE…WEND
CLS
I = 1
A = 1
B = 2
PRINT A
PRINT B
WHILE I < = 10
C = A + B
PRINT C
A = B
B = C
I = I + 1
WEND
END
Using declare sub procedure
Using FOR…NEXT
DECLARE SUB FIB ()
CLS
CALL FIB
END
SUB FIB
A = 1
B = 2
PRINT A
PRINT B
FOR I = 1 TO 10
C = A + B
PRINT C
A = B
B = C
NEXT I
END SUB
Using WHILE…WEND
DECLARE SUB FIB ()
CLS
CALL FIB
END
SUB FIB
I = 1
A = 1
B = 2
PRINT A
PRINT B
WHILE I < = 10
C = A + B
PRINT C
A = B
B = C
I = I + 1
WEND
END SUB
Program to check whether a given number is prime or composite in qbasic
‘PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR COMPOSITE
CLS
INPUT “ENTER A NUMBER”;N
FOR I = 2 TO N/2
IF N MOD I = 0 THEN
C = C+2
END IF
NEXT I
IF C>0 THEN
PRINT “IT IS COMPOSITE”
ELSE
PRINT  “IT IS PRIME”
END IF
END
Using declare sub procedure
‘CHECK WHETHER A GIVEN NUMBER IS PRIME OR COMPOSITE
DECLARE SUB A(N)
CLS
INPUT “ENTER A NUMBER”;N
CALL A(N)
END
SUB A(N)
FOR I = 2 TO N/2
IF N MOD I = 0 THEN
C = C+2
END IF
NEXT I
IF C>0 THEN
PRINT “IT IS COMPOSITE”
ELSE
? “IT IS PRIME”
END IF
END SUB
Using declare function procedure
‘PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR COMPOSITE
DECLARE FUNCTION AB (N)
CLS
INPUT “ENTER A NUMBER”; N
IF AB(N) > 0 THEN
PRINT “IT IS COMPOSITE”
ELSE
PRINT “IT IS PRIME”
END IF
END
FUNCTION AB (N)
FOR I = 2 TO N / 2
IF N MOD I = 0 THEN
C = C + 2
END IF
NEXT I
AB = C
END FUNCTION


REM PROGRAM TO CHECK ENTERED NUMBER IS UPPERCASE OR LOWERCASE
CLS
INPUT “Enter a letter”;A$
U$=UCASE$(A$)
IF U$=A$ THEN
PRINT “It is capital letter”
ELSE
PRINT “It is small letter”
ENDIF
END
USING DECLARE FUNCTION PROCEDURE
DECLARE FUNCTION UC$ (A$)
CLS
INPUT “Enter a letter”; A$
PRINT UC$(A$)
END
FUNCTION UC$ (A$)
CH$ = UCASE$(A$)
IF A$ = CH$ THEN
UC$ = “It is capital letter”
ELSE
UC$ = “It is small letter”
END IF
END FUNCTION
USING DECLARE SUB PROCEDURE
DECLARE SUB UC(A$)
CLS
INPUT “Enter a letter”; A$
CALL UC(A$)
END
SUB UC(A$)
CH$ = UCASE$(A$)
IF A$ = CH$ THEN
PRINT “It is capital letter”
ELSE
PRINT “It is small letter”
END IF
END SUB

Program to check a given number is palindrome or not in qbasic

CLS
INPUT “ENTER A NUMBER”; N
S = N
WHILE N <> 0
A = N MOD 10
R = R * 10 + A
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS PALINDROME”
ELSE
PRINT “IT IS NOT PALINDROME”
END IF
Using Declare Sub Procedure
DECLARE SUB A (N)
CLS
INPUT “ENTER A NUMBER”; N
CALL A(N)
END
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

Program to check given number is armstrong or not in qbasic

CLS
INPUT “ENTER A NUMBER”; N
S = N
WHILE N <> 0
A = N MOD 10
R = R + A ^ 3
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS ARMSTRONG”
ELSE
PRINT “IT IS NOT ARMSTRONG”
END IF
Using declare sub procedure
DECLARE SUB A(N)
CLS
INPUT “ENTER A NUMBER”; N
CALL A(N)
END
SUB A(N)
S=N
WHILE N <> 0
B = N MOD 10
R = R + B ^ 3
N = FIX(N / 10)
WEND
IF S = R THEN
PRINT “THE GIVEN NUMBER IS ARMSTRONG”
ELSE
PRINT “IT IS NOT ARMSTRONG”
END IF
END SUB

Program to reverse a given number in qbasic

CLS
INPUT “ENTER A NUMBER”; N
WHILE N <> 0
A = N MOD 10
R = R * 10 + A
N = FIX(N / 10)
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 / 8)
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 / 8)
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 / 8)
C$ = B$ + C$
WEND
O$=C$
END FUNCTION

Program to reverse a given string 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
PRINT REV$
END
Using declare sub procedure
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
PRINT REV$
END SUB
Using declare function procedure
DECLARE FUNCTION A$ (S$)
CLS
INPUT “ENTER A STRING”; S$
PRINT A$(S$)
END
FUNCTION A$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
M$ = MID$(S$, I, 1)
REV$ = REV$ + M$
NEXT I
A$ = REV$
END FUNCTION

Program to converts Hexadecimal to Decimal in Qbasic

‘THIS PROGRAM CONVERTS HEXADECIMAL TO DECIMAL
CLS
INPUT “ENTER HEXADECIMAL VALUE”;B$
FOR I=LEN(B$) TO 1 STEP -1
A$=MID$(B$,I,1)
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
Using declare function procedure
‘THIS PROGRAM CONVERTS HEXADECIMAL TO DECIMAL
DECLARE FUNCTION Z(B$)
CLS
INPUT “ENTER HEXADECIMAL 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$)
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
Z=H
END FUNCTION
Using declare sub procedure
‘THIS PROGRAM CONVERTS HEXADECIMAL TO DECIMAL
DECLARE SUB Z(B$)
CLS
INPUT “ENTER HEXADECIMAL 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$)
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
Using declare function procedure
‘THIS PROGRAM CONVERTS DECIMAL NUMBER TO BINARY
DECLARE FUNCTION A$ (N)
CLS
INPUT “ENTER A NUMBER”; N
PRINT “BINARY EQUIVALENT IS”; A$(N)
END
FUNCTION A$ (N)
WHILE N <> 0
E = N MOD 2
B$ = STR$(E)
N = FIX(N / 2)
C$ = B$ + C$
WEND
A$=C$
END FUNCTION

Program to convert Binary to Decimal in qbasic

‘THIS PROGRAM CONVERTS BINARY NUMBER TO DECIMAL
CLS
INPUT “ENTER A BINARY NUMBER”; 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
PRINT “DECIMAL VALUE IS “; M
END
Using declare sub procedure
‘THIS PROGRAM CONVERTS BINARY NUMBER TO DECIMAL
DECLARE SUB Z(B$)
CLS
INPUT “ENTER A BINARY NUMBER”; B$
CALL Z(B$)
END
SUB 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
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
INPUT “ENTER A NUMBER”;N
CALL C(N)
END
SUB C(N)
R = 1
WHILE N<>0
A = N MOD 10
R = R * A
N = FIX ( N / 10 )
WEND
PRINT “PRODUCT OF DIGITS IS”;R
END SUB
Using declare function procedure
DECLARE FUNCTION C(N)
CLS
INPUT “ENTER A NUMBER”;N
PRINT “PRODUCT OF DIGITS IS”;C(N)
END
FUNCTION C(N)
R = 1
WHILE N<>0
A = N MOD 10
R = R * A
N = FIX ( N / 10 )
WEND
C = R
END FUNCTION

Program to find the sum of the digits of the given number in Qbasic

CLS
INPUT “ENTER A NUMBER”;N
WHILE N<>0
A = N MOD 10
R = R + A
N = FIX ( N / 10 )
WEND
PRINT “SUM OF DIGITS IS”;R
END
Using declare function procedure
DECLARE FUNCTION C(N)
CLS
INPUT “ENTER A NUMBER”;N
PRINT “SUM OF DIGITS IS”;C(N)
END
FUNCTION C(N)
WHILE N<>0
A = N MOD 10
R = R + A
N = FIX ( N / 10 )
WEND
C = R
END FUNCTION
Using declare sub procedure
DECLARE SUB C(N)
CLS
INPUT “ENTER A NUMBER”;N
CALL C(N)
END
SUB C(N)
WHILE N<>0
A = N MOD 10
R = R + A
N = FIX ( N / 10 )
WEND
PRINT “SUM OF DIGITS IS”;R
END SUB

Program to print fibonacci series in Qbasic

Write a program in Qbasic to print the fibonacci series up to tenth term. Using loops-FOR…NEXT & WHILE…WEND Fibonacci series is the series in which the next number is obtained by the sum of two number just front of it. The first two numbers are explained by the user.It can be obtained up to any term.Here, I am only doing of tenth term.You can change the number of output to any term just by changing the looping number.Here is example of a fibonacci series. suppose you entered the first two numbers-1 & 2 and upto the tenth term then your output will be as:
1,2,3,5,8,13,21,34,55,89
Here in the begining 1 & 2 are the entered numbers.3 is the product of 1 & 2 as the definition of fibonacci series given in first.like wise 5 is the sum of 2 & 3 and 8 is the sum of 3 & 5 and so on..You can 
Download the source file.Here is the program.

Using FOR…NEXT
CLS
A = 1
B = 2
PRINT A
PRINT B
FOR I = 1 TO 10
C = A + B
PRINT C
A = B
B = C
NEXT I
END
Using WHILE…WEND
CLS
I = 1
A = 1
B = 2
PRINT A
PRINT B
WHILE I < = 10 
C = A + B 
PRINT C 
A = B 
B = C 
I = I + 1 
WEND 
END
Using declare sub procedure Using FOR…NEXT
DECLARE SUB FIB ()
CLS
CALL FIB
END
SUB FIB
A = 1
B = 2
PRINT A
PRINT B
FOR I = 1 TO 10
C = A + B
PRINT C
A = B
B = C
NEXT I
END SUB
Using WHILE…WEND
DECLARE SUB FIB ()
CLS
CALL FIB
END
SUB FIB
I = 1
A = 1
B = 2
PRINT A
PRINT B
WHILE I < = 10
C = A + B 
PRINT C 
A = B 
B = C 
I = I + 1 
WEND 
END SUB

Program to check whether a given number is prime or composite in qbasic

‘PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR COMPOSITE
CLS
INPUT “ENTER A NUMBER”;N
FOR I = 2 TO N/2
IF N MOD I = 0 THEN
C = C+2
END IF
NEXT I
IF C>0 THEN
PRINT “IT IS COMPOSITE”
ELSE
PRINT “IT IS PRIME”
END IF
END
Using declare sub procedure
‘CHECK WHETHER A GIVEN NUMBER IS PRIME OR COMPOSITE
DECLARE SUB A(N)
CLS
INPUT “ENTER A NUMBER”;N
CALL A(N)
END
SUB A(N)
FOR I = 2 TO N/2
IF N MOD I = 0 THEN
C = C+2
END IF
NEXT I
IF C>0 THEN
PRINT “IT IS COMPOSITE”
ELSE
PRINT “IT IS PRIME”
END IF
END SUB
Using declare function procedure
‘PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR COMPOSITE
DECLARE FUNCTION AB (N)
CLS
INPUT “ENTER A NUMBER”; N
IF AB(N) > 0 THEN
PRINT “IT IS COMPOSITE”
ELSE
PRINT “IT IS PRIME”
END IF
END
FUNCTION AB (N)
FOR I = 2 TO N / 2
IF N MOD I = 0 THEN
C = C + 2
END IF
NEXT I
AB = C
END FUNCTION

Program to check whether entered year is Leap Year or not

CLS
INPUT “Enter year to check”; Y
IF Y MOD 4 = 0 AND Y MOD 100 = 0 THEN
PRINT “This year is Leap year”; Y
ELSE
PRINT “Entered year is not leap year:”; Y
END IF


Comments

Cricketupdates said…
WAP THAT ACCEPT DECIMAL NO. CONVERT INTO OCTAL REPERSENTATION.

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PALINDROME AND ARMSTRONG PROGRAMS

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS