Wjfa CZ0 IHc 4 R NB6 G
Wjfa CZ0 IHc 4 R NB6 G
Question 1 2 3 4 5 6 7
Number
Marks 5 5 4 4 4 4 4
CO No. 1 1 1 1 1 1 1
Cognitive Level R Ap C C Ap Ap An
Note:
1. Attempt all the Seven questions available on Three pages.
2. Draw neat and clean diagrams.
3. Write all the possible steps in your solutions.
4. If you are assuming something, then clearly mention it.
5. Calculators are not allowed.
#include <stdio.h>
int main() {
int x = 5;
if (x > 0);// Empty statement! The if condition does
nothing.
printf("Positive\n"); // This executes unconditionally!
return 0;
} --------------------------------------------------------------(0.5)
d) Differentiate between a Compiler and an Interpreter.
Compiler Interpreter
Translates the entire Translates and
source code into executes the code line
machine code before by line.
execution.
Faster (because the Slower (as it
entire program is translates line by line
compiled before during execution).
execution).
Shows all errors after Stops execution at the
compilation. first error and reports
it immediately.
Creates a separate No separate file,
executable file (e.g., executes the code
.exe). directly.
int main() {
int balance = 10000, amount, choice;
while (1) {
// Display menu
printf("\n=== Bank Account Management ===\n");
printf("1. Deposit Money\n");
printf("2. Withdraw Money\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
// Deposit money
printf("Enter deposit amount: ");
scanf("%d", &amount);
if (amount > 0) {
balance += amount;
printf("Deposit successful. Updated balance: ₹%d\n",
balance);
} else {
printf("Invalid deposit amount. Must be greater
than zero.\n");
}
break;
case 2:
// Withdraw money
printf("Enter withdrawal amount: ");
scanf("%d", &amount);
if (amount <= 0) {
printf("Invalid withdrawal amount. Must be greater
than zero.\n");
} else if (amount > balance) {
printf("Insufficient balance! Withdrawal
failed.\n");
} else {
balance -= amount;
printf("Withdrawal successful. Updated balance:
₹%d\n", balance);
}
break;
case 3:
// Exit program
printf("Thank you for using our service. Final balance:
₹%d\n", balance);
return 0;
default:
printf("Invalid choice! Please select a valid
option.\n");
}
}
}
4. Write a program in C that computes the income tax to be deposited by
a salaried person to the Income Tax Office. [4]
Slab no. Salary in Rupees (Lakh) Tax
1 Less than 4,00,000 0%
2 Between 4,00,000 and 8,00,000 5%
3 Between 8,00,000 and 12,00,000 10%
4 Between 12,00,000 and 16,00,000 15%
5 Between 16,00,000 and 20,00,000 20%
6 Between 20,00,000 and 24,00,000 25%
7 Greater than 24,00,000 30%
Any employee whose salary is less than 12,00,000 must give zero tax.
Suppose the salary of an employee is 12,75,000, then the total tax will
be (Rs. 71250) computed as 0 + 20000 (i.e., slab 2) + 40000 (i.e., slab
3) + 11250 (i.e., remaining of slab 4).
#include <stdio.h>
int main() {
double salary, tax = 0;
return 0;
}
5. (a) Compute the floating-point number from the following 32-bits that
are represented by IEEE 32-bit single precision 754 floating-point
representation. [4]
0 10000111 11011000000000000000000
(−𝟏)𝟎 × 𝟐(𝟏𝟎𝟎𝟎𝟎𝟏𝟏𝟏)𝟐−𝟏𝟐𝟕 × 𝟏. (𝟏𝟏𝟎𝟏𝟏𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎)𝟐
--------(1)
= (−𝟏)𝟎 × 𝟐𝟏𝟑𝟓−𝟏𝟐𝟕 × 𝟏. 𝟖𝟒𝟑𝟕𝟓 ------(0.5)
= (−𝟏)𝟎 × 𝟐𝟖 × 𝟏. 𝟖𝟒𝟑𝟕𝟓 ------(0.5)
= 𝟒𝟕𝟐-
(b) Represent 29.625 using IEEE 32-bit single precision 754 floating-
point representation. Show all the calculations explicitly.
𝟐𝟗. 𝟔𝟐𝟓
= (−𝟏)𝟎 × 𝟐𝟒 × 𝟏. 𝟖𝟓𝟏𝟓𝟔𝟐𝟓 ------(0.5)
= (−𝟏)𝟎 × 𝟐𝟏𝟑𝟏−𝟏𝟐𝟕 × 𝟏. 𝟖𝟓𝟏𝟓𝟔𝟐𝟓 ------(0.5)
= (−𝟏)𝟎 × 𝟐(𝟏𝟎𝟎𝟎𝟎𝟎𝟏𝟏)−𝟏𝟐𝟕 × 𝟏. 𝟏𝟏𝟎𝟏𝟏𝟎𝟏𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 -------(1)