Structured Programming
SWE · Midterm · Spring 26
Paper 3 of 3Section All · Emon Mahatab NahidSwitch
Section All
Paper 3 of 3
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Daffodil International University
Faculty of Science & Information Technology
Department of Software Engineering
Mid Examination - Spring 2026
Course Code: SE 121; Course Title: Structured Programming
Sections & Teachers: All; MTK, MSS, JIC, MR, AHZ, SCS, PS
Time: 1.5 Hours
Marks: 25
Answer ALL Questions
[The figures in the right margin indicate the full marks and corresponding course outcomes. All portions of each question must be answered sequentially.]
1. a) Interpret the output and explain value changes at each step.
[Marks-4] [CLO-1 Level-2]
#include <stdio.h>
int main() {
int a=10,b=5,c=13,d,e,f,g,h;
a = ++b;
c %= a;
d = (a>c) | (a&c);
b = (c>d) ? 1 : 0;
printf("%d\n%d\n%d\n%d\n",a,b,c,d);
return 0;
}
b) Rewrite both programs in a correct and compilable form.
[Marks-6] [CLO-1 Level-2]
i) #include <stdio.h>
int main() {
char grade = "A";
int mark= 85;
float percentage = mark/10;
printf(" Percentage: %d\n", percentage);
return 0;
}
ii) #include <stdio.h>
int main(void) {
int a = 10, float b = 5.5;
if (a = 10)
printf("Equal/n");
printf("b = %f", b);
for (i = 0; i < 3; i++) {
printf("%d ", i); }
return 0;
}
2. a) A courier company uses an automated system to calculate delivery charges based on a product's weight and the distance to the delivery location. If the product weighs 5 kg or less, no extra charge is applied. For weights above 5 kg, an additional 10 taka is charged for each kilogram beyond the first 5 kg. Similarly, if the delivery distance is within 5 km, no extra charge is added. For distances greater than 5 km, an extra 20 taka is charged for each kilometer beyond the first 5 km. The total delivery charge is the sum of the weight-based and distance-based charges.
Construct a C program that takes product weight and delivery distance as input and calculates the total delivery charge.
Sample Input | Sample Output
Enter product weight: 4 | Total Delivery Charge = 0 taka
Enter delivery distance: 3 |
Enter product weight: 8 | Total Delivery Charge = 50 taka
Enter delivery distance: 6 |
[Marks-5] [CLO-2 Level-3]
b) Construct a C program using switch-case to simulate a Zombie Survival Night. A survivor starts the night with 60 health points and goes through 3 encounters.
In each encounter:
- Choosing Minor Attack (1) reduces health by 15 points
- Choosing Major Attack (2) reduces health by 30 points
- Choosing First Aid (3) increases health by 20 points
If the survivor's health drops to 0 or below, the survivor dies immediately and the program stops. After the encounters are over, display the final health and whether the survivor survived or died.
Sample Input | Sample Output
Encounter 1 : 1 | Final Health: 35
Encounter 2 : 3 | Status: Survivor survived!
Encounter 3 : 2 |
Encounter 1 : 2 | Survivor died!
Encounter 2 : 2 | Health reached 0.
[Marks-5] [CLO-2 Level-3]
c) The university library is following a very strict, policy regarding the late returns of books. The library charges a fine of 5 BDT every day for every book returned late. At the end of each day, the librarian needs to calculate the total fine received from the student for each book returned late. However, the number of late days for every book might be different.
Build a C program to calculate the total fine amount to be paid by the student using a loop.
Sample Input | Sample Output
Enter number of books: 3 | Total library fine: 35 BDT
Enter late days for book 1: 3 |
Enter late days for book 2: 4 |
Enter late days for book 3: 0 |
[Marks-5] [CLO-2 Level-3]