Programming and Problem Solving
CSE · Midterm · Fall 24
Paper 1 of 2Batch 67 · G. M. SHAHARIYAR RIYANSwitch
Batch 67
Paper 1 of 2
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 Computer Science & Engineering
Mid-Term Examination, Fall-2024
Course Code: CSE113, Course Title: Programming and Problem Solving
Level: L1 Term: T1 Batch: 67
Time: 01:30 Hrs
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. Illustrate the following expressions in detailed steps where A = 4, B = 7, C = 3, D = 2 & E = 6. Remember all the variables here are integers and for every equation the initial value of A, B, C, D & E are the same. Write each variable's value after every evaluation to obtain full marks.
CO1
a) A = (B > C) && !(D < E) || (A + B) * (C - D) / ++E
[1.5]
b) A += B++ ---C * (D / E) + (E % B)
[1.5]
2. a) Mention how many errors you can find in the following code. Explain the errors as per your understanding with line no. and why you think it as an error.
1. #include <stdio.h>
2. int main() {
3. int a = 5, b = 10;
4. float c = 15.5;
5. if (a < b, {
6. printf("a is less than b\n");
7. } else {
8. printf("a is not less than b\n");
9. }
10. for (i = 0; i < 5; i++) {
11. printf("i = %d\n", i);
12. }
13. int sum = a + b + c;
14. printf("Sum is: %f\n", sum);
15. return 0;
16. }
CO2
[2]
b) Construct the code without any errors.
[2]
3. Construct the Output for the given codes below (write only the output segment in a box):
CO3
a)
#include <stdio.h>
int main() {
float a = 5.5, b = 10.2;
int c = 3;
if ((int)a % c == 0) {
printf("Result: %.2f\n", a / c);
}
else {
printf("Result: %.2f\n", (float)((int)b % c));
}
return 0;
}
[1.5]
b)
#include <stdio.h>
int main() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (i == j) {
continue;
}
if (i + j == 4) {
break;
}
printf("i = %d, j = %d\n", i, j);
}
}
return 0;
}
[1.5]
4. Analyze the problem scenarios given below to write a full program for each of the following:
CO4
a) Recently, Bangladesh has experienced a devastating flood that has affected many lives. As a prayer for the safety of all Bangladeshis, write a simple C program that outputs the following message: May our people be safe from the flood!
[3]
Sample Input | Sample Output
NO INPUT | May our people be safe from the flood!
b) The recent flood has affected many lives. A team of relief workers is collecting foodgrains from different regions to help those in need. They have collected (A) kg of foodgrains from Dhaka, (B) kg from Chittagong, and (C) kg from Rajshahi. Unfortunately, (D)% of the foodgrains are lost during transportation. Write a C program to calculate the amount of foodgrains that will actually be delivered.
[4]
Input: Four floating point numbers A, B, C & D as described above.
Output: The program should output the total amount of foodgrains delivered, formatted to two decimal places, in the following format:
A total of X.XX kg of foodgrains delivered
Sample Input | Sample Output
100.0 150.0 200.0 10.0 | A total of 405.00 kg of foodgrains delivered
Sample Input | Sample Output
50.5 75.75 100.25 5.0 | A total of 215.18 kg of foodgrains delivered
c) A team of rescue workers is tasked with delivering relief packages to various flood affected areas. Each package contains a certain number of essential items. The team will visit multiple locations, and the number of packages delivered at each location will be given as input. Write a C program to calculate the total number of packages delivered.
[4]
Input: The program will take the following inputs:
o An integer n representing the number of locations.
o n integers representing the number of packages delivered at each location.
Output: The program should output the total number of packages delivered in the following format:
A total of X packages delivered
Sample Input | Sample Output
3
10 20 30 | A total of 60 packages delivered
Sample Input | Sample Output
4
5 15 25 10 | A total of 55 packages delivered
d) A team of rescue workers is tasked with distributing relief packages to various flood affected areas. Each area will receive a certain number of packages. The team will visit multiple locations, and the number of packages delivered to each location will be stored in an array. Write a C program to calculate the total number of packages delivered and print the number of packages delivered to each location that received more than a specified threshold.
[4]
Input: The program will take the following inputs:
o An integer n representing the number of locations.
o An array of n integers representing the number of packages delivered to each location.
o An integer t representing the threshold number of packages.
Output: The program should output the total number of packages delivered and the number of packages delivered to each location that received more than the threshold, in the following format:
A total of X packages delivered
Locations with more than Y packages:
Location i: Z packages
Sample Input | Sample Output
3
10 20 30
15 | A total of 60 packages delivered
Locations with more than 15 packages:
Location 2: 20 packages
Location 3: 30 packages
Sample Input | Sample Output
4
5 15 25 10
10 | A total of 55 packages delivered
Locations with more than 10 packages:
Location 2: 15 packages
Location 3: 25 packages