9 class related QBASIC programs with solutions
d) Program to print 5 Number in Ascending
Order
Dim
n(5)
for
i = 1 to 5
input
"Enter any five number"; n(i)
next
i
for
i = 1 to 5
for
j = 1 to 5-1
if
n(J)>n(j+1) then swap n(j),n(j+1)
next
j
next
i
print
"the number in ascending order"
for
i = 1 to 5
print
n(i);
next
i
end
E)To find the factorial of given number.
CLS
INPUT "Enter any number"; n
f = 1
FOR i = 1 TO n
f = f * i
NEXT i
PRINT "The factorial of input number is"; f
END
INPUT "Enter any number"; n
f = 1
FOR i = 1 TO n
f = f * i
NEXT i
PRINT "The factorial of input number is"; f
END
F ) WAP to enter any three
numbers and display the greatest one.
CLS
INPUT
“ENTER ANY THREE NUMBERS”; A, B, C
IF
A > B AND A > C THEN
PRINT
A; “IS GREATEST”
ELSEIF
B > A AND B > C THEN
PRINT
B; “IS GREATEST”
ELSE
PRINT
C; “IS GREATEST”
END
IF
END
G] WAP to enter any three
numbers and display the smallest one.
REM
CLS
INPUT
“ENTER ANY THREE NUMBERS”; A, B, C
IF
A < B AND A < C THEN
PRINT
A; “IS SMALLEST”
ELSEIF
B < A AND B < C THEN
PRINT
B; “IS SMALLEST”
ELSE
PRINT
C; “IS SMALLEST”
END
IF
END
H] WAP to enter any three numbers and display
the middle number.
INPUT
“ENTER ANY THREE NUMBERS”; A, B, C
IF
A > B AND A < C OR A < B AND A > C THEN
PRINT
A; “IS MIDDLE NUMBER”
ELSEIF
B > A AND B < C OR B < A AND B > C THEN
PRINT
B; “IS MIDDLE NUMBER”
ELSE
PRINT
C; “IS MIDDLE NUMBER”
END
IF
END
I] WAP to input
number and check whether the given no. is prime or composite.
CLS
INPUT "ENTER ANY NUMBER"; N
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT N; "IS PRIME NUMBER"
ELSE
PRINT N; "IS COMPOSITE NUMBER"
END IF
END
J] WAP to check and print
whether the entered number is Armstrong or not.
CLS
INPUT "enter any number
:"; num
n = num
sum = 0
WHILE num <> 0
r = num MOD 10
num
= num \ 10
sum = sum + (r * r * r)
WEND
IF n = sum THEN
PRINT "Armstrong Number"
ELSE
PRINT "Not Armstrong Number"
END IF
END
K]
WAP to input any number and check whether the given no. is divisible by 3 and 7
or not.
INPUT
“ENTER ANY NUMBER”; N
IF
N MOD 3 = 0 AND N MOD 7 = 0 THEN
PRINT
N; IS COMPLETELY DIVISIBLE BY 3 AND 7”
ELSE
PRINT
N; IS NOT COMPLETELY DIVISIBLE BY 3 AND 7”
END
IF
END
L] WAP to convert decimal
number to binary number.
CLS
INPUT "ENTER DECIMAL
NUMBER"; D
WHILE D < > 0
R = D MOD 2
S$ = STR$(R) + S$
D = D \ 2
WEND
PRINT "BINARY
EQUIVALENT VALUE="; S$
END
M] WAP to convert
binary number to decimal equivalent
CLS
INPUT "ENTER BINARY
NUMBER"; N$
FOR I = LEN(N$) TO 1 STEP
-1
B$ = MID$(N$, I, 1)
S = S + VAL(B$) * 2 ^ P
P = P + 1
NEXT I
PRINT "DECIMAL
EQUIVALENT VALUE="; S
END
Alternative method
CLS
Input "enter a binary number"; n
While
n<>0
r=n mod
10
sum = sum
+r*2^p
n = n\10
p = p+1
wend
Print "Decimal number is"; sum
END
N] WAP to input any number and check
whether the given no. is positive, negative or zero.
INPUT
“ENTER ANY NUMBER”; N
IF
N > 0 THEN
PRINT
N; IS POSITIVE NUMBER”
ELSEIF
N < 0 THEN
PRINT
N; IS NEGATIVE NUMBER”
ELSE
PRINT
N; IS ZERO”
END
IF
END
O] WAP to find and
print repetition of any character in an user entered sentence.
CLS
INPUT
"Enter any string"; a$
Input
"Enter the character which you want to count"; w$
for I = 1 to len(a$)
b$ = MID$(a$,I ,1)
if b$ = w$ THEN c=c+1
Next
i
print
"Repeated character is" ; c
end
P]
WAP to input a string then print it in the reverse order.
CLS
INPUT "Enter the string"; a$
FOR i = LEN(a$) TO 1 STEP -1
b$ = MID$(a$, i, 1)
r$ = r$ + b$
NEXT i
PRINT "The reverse of the string is "; r$
END
INPUT "Enter the string"; a$
FOR i = LEN(a$) TO 1 STEP -1
b$ = MID$(a$, i, 1)
r$ = r$ + b$
NEXT i
PRINT "The reverse of the string is "; r$
END
Q] WAP
to input any string and count total no. of words.
CLS
INPUT
"ENTER ANY STRING"; S$
WC =
1
FOR
I = 1 TO LEN(S$)
B$ =
MID$(S$, I, 1)
IF
B$ = " " THEN
WC =
WC + 1
END
IF
NEXT
I
PRINT
"TOTAL NO. OF WORDS= "; WC
END
SUB
R] WAP to check whether an entered word
is palindrome or not.
CLS
INPUT "Enter a word: "; w$
FOR i = LEN(w$) TO 1 STEP -1
rev$ = rev$ + MID$(w$, i, 1)
NEXT i
PRINT
PRINT "The original word is "; LCASE$(w$)
PRINT "The reverse word is "; LCASE$(rev$)
PRINT
IF LCASE$(w$) = LCASE$(rev$) THEN
PRINT "The word is a palindrome"
ELSE
PRINT "The word is not a palindrome"
END IF
END
INPUT "Enter a word: "; w$
FOR i = LEN(w$) TO 1 STEP -1
rev$ = rev$ + MID$(w$, i, 1)
NEXT i
PRINT "The original word is "; LCASE$(w$)
PRINT "The reverse word is "; LCASE$(rev$)
IF LCASE$(w$) = LCASE$(rev$) THEN
PRINT "The word is a palindrome"
ELSE
PRINT "The word is not a palindrome"
END IF
END
S] WAP to input any word and count total
no. of vowels and consonants.
CLS
INPUT
"ENTER ANY WORD"; S$
VC =
0
CC =
0
FOR
I = 1 TO LEN(S$)
B$ =
MID$(S$, I, 1)
C$ =
UCASE$(B$)
IF
C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ =
"O" OR C$ = "U" THEN
VC =
VC + 1
ELSE
CC =
CC + 1
END
IF
NEXT
I
PRINT
"TOTAL NO. OF VOWELS= "; VC
PRINT
"TOTAL NO. OF CONSONANTS="; CC
Q.N
2] Write programs to display the following numeric series:
a) 1 4
9 16 25 …..100 b)
1 2 4 7 11 …10th term.
CLS Cls
For I = 1 to 10 a = 1
s= i*I for I = 1 to 10
Print
s; print a;
next
I a=a+i
end next
i
end
e) 1
1 2 3 5 8 10 th term
CLS.
a=1
b=1
print a; b;
For I = 1 to 8
c= a+b;
print c;
a=b
b=c
next i
end
print a; b;
For I = 1 to 8
c= a+b;
print c;
a=b
b=c
next i
end
Comments
Post a Comment