Programming and Problem Solving
CSE · Midterm · Fall 23
Batch 65
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Daffodil International University
Department of Computer Science & Engineering
Faculty of Science & Information Technology
Mid-Semester Examination
Semester: Fall 2023
Course Code: CSE 113
Course Title: Programming & Problem Solving
Level: 1
Term: 1
Batch: 65
Time: 1.5 hours
Full Marks: 25
Answer all of the following Questions
Q1. Expression Evaluation: Illustrate the following expressions in detailed steps where A = 5, B = 2, C = 4, D = 1 & E = 7. 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 a full mark. [3]
a) B = C || A - A && C + D * E / B ++ [1.5]
b) C -= B | E && D & A % D % C * B [1.5]
Q2. Demonstrate Error Finding & Bug Fixing: [4]
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. [2]
1. &include<stdoi.h>
2. float main()
3. {
4. int x=10, char c = x;
5. while(1) {
6. if (x > 101 )
7. break;
8. prirtf ( "X = \"%c\" & a= %d\n", x, c ) ;
9. c = x++;
10. }
11. return 2.0;
12. }
b) Construct the code without any errors. [2]
Q3. Construct the Output for the given codes below (write only the output segment in a box) : [3]
a) [1.5]
#include<stdio.h>
int main() {
char x = 'A'; // ASCII value of 'A' = 65
while( x < 'E') {
int b = x++;
if(++b > 67)
break;
printf ("b=\"%c\" & x=\"%d\"\n", b, x);
x = x++;
}
return 0;
}
b) [1.5]
#include<stdio.h>
void main () {
int m = 2, n = 10;
for (int i = m; i <= m * m; i++)
while (n % 3 != 0)
printf("M=%d X N=%d =%03d\n", n, m, n * m);
n ++;
return 0;
}
Q4. Analyze the problem scenarios given below to write a full program for each of the following [15]
a) Bangladesh is one of the developing countries in the world. But Dengue has been spreading throughout the whole country. As a good citizen and a good programmer you want to raise awareness among the country's people by two slogans "Small Bite, Big Threat." & "Keep Your Surrounding Mosquitoes Free.". Now write a C program to print the slogans in separate lines. [4]
Sample Input | Sample Output
NO INPUT | Small Bite, Big Threat.
| Keep Your Surrounding Mosquitoes Free.
b) Dengue has become one of the most dangerous diseases in recent years. Every year the government of Bangladesh declares one district as Red Zone on the basis of the number of dengue patients admitted in hospital. As you are a renowned good programmer, this year the government appoints you for doing this job. [4]
Input: Two integers A, B. A is the number of people that are affected by dengue in district 1, B is the number of people that are affected by dengue in district 2.
Output: Print a line saying "X is in the Red Zone", here X is either District-1 or District-2 depending on which district has more patients.
Sample Input | Sample Output
95 3 | District-1 is in the Red Zone
c) As dengue has been spreading day by day in a tremendous way, the government has been taking the decision to spray mosquito killer throughout the country. This initiative has been applied to Dhaka city for the very first time as Dhaka is in the Red zone. But there are lots of areas in Dhaka city. The budget that has been approved for this sector is limited. The supply of mosquito killer spray is limited. As you are a programmer you have to tell if the government can free Dhaka city from dengue or not. You are given two integers N, M which is the number of areas in Dhaka city and the amount of mosquito killer that the government supplies in Dhaka city. In the next line you have N numbers separated by a space that are the amount of mosquito killer needed for each area. All you have to do is print "Dhaka Baicha Gese!" if the government can supply the amount needed. Otherwise print "Sesh Dhaka Sesh!" [4]
Input: Two integers N, M representing the number of areas in dhaka city and the amount of mosquito killer supplied by the government,
Output: Print "Dhaka Baicha Gese!" if the amount of supplied mosquito killer is sufficient otherwise print "Sesh Dhaka Sesh!" (without Quote)
Sample Input | Sample Output
5 18
4 5 3 2 3 | Dhaka Baicha Gese!
d) A magical madman arrived in the dream of the all Bangladesh Govt. high officials said you can only save people from Dengue only if their age is more than 20. [3]
Input: Starts with an integer N that defines the number of people in Bangladesh. Followed by N integers in the next line where each value represents the age of the individual person.
Output: In a line show "Saved All" if you can save each and every one. Otherwise output will consist of 2 lines. The first line shows "Only few are saved and the following are dead :". The second line shows all the ages of persons that died and could not be saved.
Sample Input | Sample Output
5
7 22 19 21 20 | Only few are saved and the following are dead :
| 7 19 20
Sample Input | Sample Output
5
27 22 199 21 201 | Saved All