Monday Batch1&2 test-1 question paper solution

  1. 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.
WhatsApp Group Join Now
Telegram Group Join Now

Dry Run for Input: 135


Initialization

VariableValue
n135
t135
c0
s0
d0

First WHILE Loop: Count digits

Stepn (before)n \ 10c (after)
1135131
21312
3103
  • After loop: n = 0, c = 3

Reset n = t (135)


Second WHILE Loop: Sum of digits powered by position

Stepnd = n MOD 10cd ^ cs (after)n = n \ 10
1135531250 + 125 = 12513
213329125 + 9 = 1341
31111134 + 1 = 1350
  • After loop: s = 135, n = 0

Final Check

ConditionResult
s = t135 = 135 → True

Output:

“disarium no”

2. Write a program to print the first 10 Fibonacci numbers in reverse order.

Dry Run in Table Format

iInner Loop Range (j)Final Value of c (i-th Fibonacci number)
91 to 934
81 to 821
71 to 713
61 to 68
51 to 55
41 to 43
31 to 32
21 to 21
11 to 11
0None (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

VariableValue
n145
t145
s0

WHILE Loop Breakdown

Stepnd = n MOD 10Factorial of d (f)s = s + fn = n \ 10
114551200 + 120 = 12014
214424120 + 24 = 1441
3111144 + 1 = 1450

Final Check

VariableValue
s145
t145

Since s = tThe 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
11 to 5Always true (first row)*****
21j=1 → true*
2, 3, 4false(space)
5j=L → true*
31j=1 → true*
2, 3, 4false(space)
5j=L → true*
41 to 5Always 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 of j in a row.

Dry Run for n = 4

Loop Values and Outputs:

i (Row)j (Column)n - j + iOutput Row
114 – 1 + 1 = 4
24 – 2 + 1 = 3
34 – 3 + 1 = 24 3 2
44 – 4 + 1 = 1
214 – 1 + 2 = 5
24 – 2 + 2 = 4
34 – 3 + 2 = 35 4 3
314 – 1 + 3 = 6
24 – 2 + 3 = 56 5
414 – 1 + 4 = 77

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 from h to 1 (decreasing)
  • Inner loop: prints c + j for each column j from 1 to i

Dry Run with h = 4

Variable table:

Row (i)c Before LineInner Loop (j from 1 to i)Values Printed (c + j)c After Line
421 to 43 4 5 63
331 to 34 5 64
241 to 25 65
151 to 166

Logic 2:

Logic Explained:

  • Outer loop: i from 1 to h (number of rows).
  • Inner loop: j starts from i + 2 to h + 2.
  • Each line prints a range of numbers starting from i + 2 up to h + 2.

Dry Run with h = 3


Table: Loop Execution

Row (i)j from i+2 to h+2Values Printed
13 to 53 4 5
24 to 54 5
35 to 55

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

Leave a Comment