Skip to content

Programming and Problem Solving

CSE · Final · Fall 23

Batch 65

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 & Engineering Faculty of Science & Information Technology Final Term Examination Semester: Fall 2023 Course Code: CSE 113 Course Title: Programming & Problem Solving Level: 1 Term: 1 Batch: 65 Time: 2.0 hours Full Marks: 40 Answer all of the following Questions Q1. Demonstrate Error Finding & Bug Fixing: [6] CO2 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. struct employee 3. { 4. int id, 5. float salary; 6. }; 7. int main() 8. { 9. employee e1,e2; 10. e1.id=2001;e1.salary=90, 11. e2.id=2002;e2.salary=80; 12. printf("First employee id: %d & salary: %d\n", e1.id,e1->salary); 13. printf("Second employee id:%f & salary: %fn", e2>id,e2.salary); 14. return 20; 15. } b) Construct the code without any errors. Q2. Construct the Output for the given codes below (write only the output segment in a box): [9] CO3 a) #include<stdio.h> void hel(int x) { while(x- >= 0) { printf("N holo %d\n",x*x); x++; } return; } int main() { int n=10; hel(n); return 0; } b) #include<stdio.h> int main() { int m=20,n=30; int *p,*q; p=&n,q=&m; *p *= m, *q *= n; printf("m=%d n=%d\n",*q,n); printf("p=%d q=%d\n",*p,m); return 0; } c) #include<stdio.h> int main() { int ar[3][3]={{5,2,3},{2,1,3},{2,2,2}},i,j; for(i=0;i<3;i++) { for(j=i;j<3;j++) { printf("I=%d J=%d\n", ar[i][j]*i,ar[i][j]); } } } Q3. Analyze the problem scenarios given below to write a full program for each of the following: [25] CO4 a) Recently Apple released the Iphone 15 Series. They launched three mobile phones of 15 series: Iphone 15, Iphone 15 pro & Iphone 15 pro max. But one of the saddest things about these phones is that Apple does not provide a charger with the mobile. The user has to buy a charger externally. Mr. Tamim Iqbal is the former captain of "Mayer Doa Cricket Team" is going to be the captain again after the world cup. In these circumstances he wants to buy a new Iphone from the 15 series as he is a fan of the Iphone. But he does not have enough money to buy an original charger with the mobile, as he did not get the salary of the previous month from the "Mayer Doa Cricket Board". So, he planned to buy a duplicate charger that was manufactured by china. There are three types of charger that China manufactured for the Iphone 15 series. You have to help Tamim Iqbal by finding the cheapest one from them. Input: There will be three integers that are the prices of the three chargers. Output: Show the cheapest price of the charger. Sample Input | Sample Output 2000 5000 1500 | 1500 b) To qualify Main Round of Take-Off Programming Contest you have to participate in the preliminary round. There are some criteria by which the students are selected from preliminary round to main round. You go through the rules and you find that it is complex to calculate. You don't want to do the complex calculation and you make a rule for yourself that by maintaining the rule you believe that you can qualify to the main round. The rule is you have to solve a minimum number of problems to qualify in the main round. Input: In the first line you have to take an integer number N, representing the number of problems in the contest. In the next line you have to input N integers that represent the problems' verdicts (here 1 means you got accepted on the problem and 0 means you got the wrong answer). The last line there will be an integer X, that represents the minimum number of problems you have to solve to qualify for the main round. Output: Show "Yes, I Will qualify!" if you have qualified for the main round, otherwise show "I am sorry!". Sample Input | Sample Output 6 1 0 1 1 1 1 4 | Yes, I Will qualify! 6 1 0 1 0 0 1 4 | I am sorry! Explanation: In the first sample you have solved 5 problems and the number of problem counts to qualify in the main round was 4, so you qualified for the contest. c) So, Almost you have completed the Programming and Problem Solving Course. Advanced Congratulations if you will pass this course. You tried hard and practiced problems each day and performed very well. I am your course teacher in this course and I want to give you an opportunity to get an experience of Student prefect with me in the next semester. I want to give a prize to my section's students based on the weekly performances in the next semester to motivate the students. As you are the best programmer of the previous course, I am given the responsibility to find out the best weekly performance. You will be given the day wise problem solve count of a week of students of the class serially from roll 1, you have to find out the best one. Input: In the first line there will be an integer N, the number of students in the class. Then there will be N lines and each line will contain 7 integers that are the solve count of 7 days of the students. Output: Show the student roll number, who have solved the most problems in the format "Roll - X is performer of the week.", where X is the roll number. Sample Input | Sample Output 3 2 3 0 1 0 1 1 3 2 4 1 0 1 1 4 1 1 1 1 1 1 | Roll - 3 is performer of the week. Explanation: Roll-1 student solve count = 8. Roll-2 student solve count = 10. Roll-3 student solve count = 12. d) Recently you are learning C Programming language and your teacher taught you a new topic about String. String is the combination of multiple characters, digits or symbols. As your teacher taught you about string already so he gives you a task. He told you to pick a name and gave you two characters X, Y and told you from that name you have to replace all the X with Y. As you are a good programmer and doing good at programming, he expects you to solve this problem and satisfy him. Input: In the first line there will be a string S (it will have no space and contains only uppercase and lowercase characters). In the next two lines there will be two characters X and Y. Output: You have to print a new string from S replacing character X by character Y ( For more clarification see the sample input output) Sample Input | Sample Output MehedyHasanMiraz a e | MehedyHesenMirez Explanation: In the Sample Input, you have to replace all the characters 'a' with 'e' in the string. e) From childhood you love digits. You love to play with digits. Recently you have learned about programming and are learning more and more new topics in programming languages. Today your teacher has teached you about recursion. Recursion is one of the most fascinating topics in programming because when you think about a problem and want to solve it with recursion you need to make your own imaginary visualization of how it can manipulate your code using a few lines of code. As you love digits and learn about recursion you want to solve a Sum Of Digit problem using recursion. You have already solved this problem using loop but now as you learn about recursion you want to solve this problem using recursion. You don't need to do many things. All you have to do is You will be given a number N. You have to do a sum of all digits of this number N(using recursion) and show the result as output. Input: You are given a number N. Output: Print the sum of the digits of N(using recursion) Sample Input | Sample Output 54321 | 15