- Write a program in QBASIC to accept a number from the user and check if it is a Disarium number or not.
Ex- 135->11+32+53= 135.

Dry Run for Input: 135
Initialization
Variable | Value |
---|---|
n | 135 |
t | 135 |
c | 0 |
s | 0 |
d | 0 |
First WHILE Loop: Count digits
Step | n (before) | n \ 10 | c (after) |
---|---|---|---|
1 | 135 | 13 | 1 |
2 | 13 | 1 | 2 |
3 | 1 | 0 | 3 |
- After loop:
n = 0
,c = 3
Reset n = t
(135)
Second WHILE Loop: Sum of digits powered by position
Step | n | d = n MOD 10 | c | d ^ c | s (after) | n = n \ 10 |
---|---|---|---|---|---|---|
1 | 135 | 5 | 3 | 125 | 0 + 125 = 125 | 13 |
2 | 13 | 3 | 2 | 9 | 125 + 9 = 134 | 1 |
3 | 1 | 1 | 1 | 1 | 134 + 1 = 135 | 0 |
- After loop:
s = 135
,n = 0
Final Check
Condition | Result |
---|---|
s = t | 135 = 135 → True |
Output:
“disarium no”
2. Write a program to print the first 10 Fibonacci numbers in reverse order.

Dry Run in Table Format
i | Inner Loop Range (j ) | Final Value of c (i-th Fibonacci number) |
---|---|---|
9 | 1 to 9 | 34 |
8 | 1 to 8 | 21 |
7 | 1 to 7 | 13 |
6 | 1 to 6 | 8 |
5 | 1 to 5 | 5 |
4 | 1 to 4 | 3 |
3 | 1 to 3 | 2 |
2 | 1 to 2 | 1 |
1 | 1 to 1 | 1 |
0 | None (loop not run) | 0 |
Final Output on Screen:
34
21
13
8
5
3
2
1
1
0
3. Write a program to accept a number from the user and check if it is a Krishnamurti number or not.

Krishnamurti/Strong Number/Special no
A number is called a Krishnamurti number if the sum of factorials of its digits equals the number itself.
Examples:
- 145 → 1! + 4! + 5! = 1 + 24 + 120 = 145
- 2 → 2! = 2
- 40585 → 4! + 0! + 5! + 8! + 5! = 40585
Dry Run for Input 145
Initial Values
Variable | Value |
---|---|
n | 145 |
t | 145 |
s | 0 |
WHILE Loop Breakdown
Step | n | d = n MOD 10 | Factorial of d (f ) | s = s + f | n = n \ 10 |
---|---|---|---|---|---|
1 | 145 | 5 | 120 | 0 + 120 = 120 | 14 |
2 | 14 | 4 | 24 | 120 + 24 = 144 | 1 |
3 | 1 | 1 | 1 | 144 + 1 = 145 | 0 |
Final Check
Variable | Value |
---|---|
s | 145 |
t | 145 |
Since s = t
The program prints:
Output:
krishnamurti no
4.Write a program to accept the length breadth of a rectangle and print a hollow rectangle.


Goal:
Print a rectangle of size B x L
with stars on the border and spaces inside.
Dry Run Example
Let’s use:
L = 5
(columns)B = 4
(rows)
Output on Screen:
*****
* *
* *
*****
Loop Table Breakdown
i (row) | j (column) | Condition (i=1 OR i=B OR j=1 OR j=L ) | Output |
---|---|---|---|
1 | 1 to 5 | Always true (first row) | ***** |
2 | 1 | j=1 → true | * |
2, 3, 4 | false | (space) | |
5 | j=L → true | * | |
3 | 1 | j=1 → true | * |
2, 3, 4 | false | (space) | |
5 | j=L → true | * | |
4 | 1 to 5 | Always true (i = B = 4 ) | ***** |
5.Write a program to accept the row height from user and print the following pattern.
a)
54321
6543
765
87
9

Logic:
- The outer loop runs from
i = 1 TO n
(rows). - The inner loop runs from
j = 1 TO n - i + 1
(columns per row). - It prints
n - j + i
for each value ofj
in a row.
Dry Run for n = 4
Loop Values and Outputs:
i (Row) | j (Column) | n - j + i | Output Row |
---|---|---|---|
1 | 1 | 4 – 1 + 1 = 4 | |
2 | 4 – 2 + 1 = 3 | ||
3 | 4 – 3 + 1 = 2 | 4 3 2 | |
4 | 4 – 4 + 1 = 1 | ||
2 | 1 | 4 – 1 + 2 = 5 | |
2 | 4 – 2 + 2 = 4 | ||
3 | 4 – 3 + 2 = 3 | 5 4 3 | |
3 | 1 | 4 – 1 + 3 = 6 | |
2 | 4 – 2 + 3 = 5 | 6 5 | |
4 | 1 | 4 – 1 + 4 = 7 | 7 |
b)
34567
4567
567
67
7
Ans: Logic 1:

Explanation:
h
= height (user input)c
starts at 2 and increments by 1 after each row- Outer loop:
i
goes fromh
to1
(decreasing) - Inner loop: prints
c + j
for each columnj
from 1 toi
Dry Run with h = 4
Variable table:
Row (i) | c Before Line | Inner Loop (j from 1 to i) | Values Printed (c + j ) | c After Line |
---|---|---|---|---|
4 | 2 | 1 to 4 | 3 4 5 6 | 3 |
3 | 3 | 1 to 3 | 4 5 6 | 4 |
2 | 4 | 1 to 2 | 5 6 | 5 |
1 | 5 | 1 to 1 | 6 | 6 |
Logic 2:

Logic Explained:
- Outer loop:
i
from 1 toh
(number of rows). - Inner loop:
j
starts fromi + 2
toh + 2
. - Each line prints a range of numbers starting from
i + 2
up toh + 2
.
Dry Run with h = 3
Table: Loop Execution
Row (i ) | j from i+2 to h+2 | Values Printed |
---|---|---|
1 | 3 to 5 | 3 4 5 |
2 | 4 to 5 | 4 5 |
3 | 5 to 5 | 5 |
6. Find the output of the following:
i)PRINT ASC(“INDIAN”)—–>73
ii)PRINT CHR$(ASC(“E”)+5)—–>J
iii)PRINT 45+”XY”—–>Type mismatch/cannot convert number to string/error
iv)PRINT CINT(-32767.5)—–>-32768
v)PRINT FIX(ABS(-35.56))—–>35
vi)PRINT SGN(-24+25)—–>1
vii)PRINT FIX(-34.67)—–>-34
viii)PRINT INT(-17.89)—–>-18
ix)A$=”COMPUTER APPLICATION”
PRINT MID$(A$,2,5)—–>OMPUT
x)A$=”SACHIN TENDULKAR”
MID$(A$,2,5)=”TTCA”
PRINT A$—–>STTCAN TENDULKAR