Skip to content

Programming and Problem Solving

CSE · Midterm · Fall 21

Section All

This browser can’t show the PDF here

Open it, and your phone’s PDF viewer takes it, or download it.

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 and Engineering Faculty of Science & Information Technology Midterm Exam Examination, Fall 2021 @ DIU Blended Learning Center Course Code: CSE122 (Day), Course Title: Programming and Problem Solving Level: 1 Term: 2 Section: All Instructor: All Modality: Open Book Exam Date: Saturday 13 November, 2021 Time: 09:00am-11:30am Two and half hours (2:30), Marks: 25 Directions: Students need to go through the CASE STUDY shown in this exam paper. Analyze and answer specific sections based on your own thinking and work. Do not share as this will be treated as plagiarism by Blended Learning Center. Part – I (Expression Evaluation): [4.0] If your ID is 211-15-14741 then A= 21 (first two digits of your ID), B=741 (last three digits of your ID), C= 1 (last digit of your ID) and D = 4 (sum of first three digits of your ID). If there is a 0 in the last five digits of your ID then replace it with 9 first and then calculate the value of A,B,C and D. Remember all the variable here are integers. Evaluate the following expressions using the value of A, B, C & D. [To obtain the full marks you have to evaluate the expression line by line. Direct answer may fetch you 25% or less marks] a) ((A % D) || B) * C + D + A * D [2] b) A + D * C - D – (( A && D) + B / A) [2] Part – II (Error Finding & Bug Fixing): [4.0] a) Mention how many errors you can find in the following code. Explain the errors as per your understanding [If you write the exact errors like a compiler it will not be counted] with line no. and why you think it as an error. [2.5] 1. #include<stdio.c> 2. Int main() 3. { 4. int a = 13, int b = 39, int w = 0; 5. for(;a<b;a++) 6. { 7. if(a%2==1) 8. w += a; 9. } 10. if(w%2==0) 11. Printf(w is even); 12. return0; 13. } b) Rewrite the code without any errors. [1.5] Part – III: (Output Tracing): [4.0] [User input in the problem (a) will be the last three digits of your ID. For the problem (b) user input is the last digit of your id. If there is a 0 in the last three digits of your ID then replace it with 6] a) #include<stdio.h> int main() { int id, i, c = 0; scanf("%d", &id); for(i=20;i<id;i++) { if(i%2==1) c=i&&id; } if(++id) printf("%d %d %d\n", id, ++i, c); return 0; } [2] b) #include<stdio.h> int main() { int id, a, b, c; scanf("%d", &id); switch(id) { case 1: a=2;b=1;c=2;break; case 2: a=4;b=-2;c=5;break; case 3: a=-2;b=3;c=6;break; default: a=b=c=0; } int temp = ++a; a = --b; b = ++temp; printf("%d %d %d %d", id, a, b, c); return 0; } [2] Part IV (Full Program Writing): [read the notes carefully] [13.0] a) A Monster has attacked our planet earth but he is harmless. All he wants to know is your name, address, and hobby. In order to provide that information, you need to write a c program that will print your name, address, and hobby in three different lines. [3.0] [If your name is Ashif Raihan then sample output could be the following] Sample Input | Sample Output - | Ashif Raihan - | 130/1, Dhaka 1209 - | Reading [Note: There is no input for this problem] b) After finishing the Programming and Problem-Solving exam you and your friends are planning to go to PizzaBurg. The cost of the pizza you want to have is last three digits of your ID. The amount of money you have is the absolute difference between a and b plus the sum of c and d plus the multiplication of e and f. Here a, b, c, d, e and f are user inputs. Now write a program to calculate whether you have enough money to afford your favorite pizza at PizzaBurg or not. If yes then print "Yeah!! let's have pizza!!", If no then print "Oh no!! let's get something else". [3] Sample Input | Sample Output 234 | Yeah!! let's have pizza!! 12 10 131 47 11 5 | [Note: The first line of input is the last three digits of your id. The second line of input represents a, b, c, d, e, and f respectively.] c) Suppose you have an integer array of size N which means the array has N integer numbers. Your task is to find the maximum and minimum difference among those N elements. Then find the sum of the maximum and minimum differences. [4] Sample Input | Sample Output 4 | 2 15 2 7 4 | 13 - | 15 [Note: The first line of input is the size of the array. The second line of the input contains array elements. The first line of the output is the minimum difference, the Second line is the maximum difference. The third line of the input is the sum of minimum and maximum difference] d) Suppose you are trapped in a planet called "nowhere". Everything is very strange on that planet, the sun never sets, food is also strange. You really want to get back to earth. In order to get back to earth, you will have to solve a problem they provide. If you can solve the problem you will be rewarded and sent straight back to earth, if no then you will be stuck on that planet. Problem is as follows. [3] Take four user inputs p, q, id, and k. Then find all the numbers that are divisible by the id and greater than k in the range of p and q. Sample Input | Sample Output 50 20 | 36 3 | 39 33 | 42 - | 45 - | 48 [Note: The first line of input is the integer p, q. The second line of the input is the integer id, which is the last digit of your id. The third line of the input is the integer k. Outputs contain the numbers that are divisible by id and greater than k in a range of p and q.] Good Luck!!!