Programming and Problem Solving
CSE · Midterm · Summer 26
Paper 1 of 2Batch 71 · Md. Ferdous Foysal HridoySwitch
Batch 71
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
Midterm Examination, Summer 2026
Course Code: CSE113, Course Title: Programming and Problem Solving
Level: 1 Term: 2 Batch: 71
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. Analyze the following C program and answer the questions below:
#include <stdio.h>
int main() {
int arr[5] = {4, 7, 2, 9, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
sum += arr[i];
}
printf("Sum = %d\n", sum);
return 0;
}
a) Identify and list all operators and identifiers used in the given C program. [02]
b) Modify the program to calculate the sum of odd numbers in the array [02]
2. a) Identify the syntax errors in the following code snippet. Write down each error with the line number and why you think this is an error:
1 #include <stdio.h>
2 int main() {
3 int arr[6] = {10, 25, 25, 18, 7, 15};
4 int largest = arr[0];
5 int secondLargest = arr[-1];
6 for(i = 1; i < 6; i++) {
7 if(arr[i] > largest) {
8 secondLargest = largest;
9 largest = arr[i];
10 } else if(arr[i] => secondLargest && arr[i] != largest) {
11 secondLargest = arr[i];
12 }
13 }
14 printf("Second Largest Element = %d\n", secondLargest);
15 return 0;
16 }
[02]
b) Write a corrected version of the above program. [02]
c) Generate the output of given code below (write only the output segment in a box): [02]
#include <stdio.h>
int main()
{
for (int i = 0; i < 5; i++)
{
if (i % 4 == i / 3) {
printf("#");
}else {
printf(".");
}
if (i % 3 == 0) {
printf("\n");
}
}
return 0;
}
3. Identify the problem scenarios given below and write a complete C program for each problem statement.
a) A small juice shop named "Fresh Sip" sells fruit juice bottles. A customer buys some bottles and wants to share them equally among friends. Your task is to write a C program that finds how many bottles each friend gets and how many bottles are left.
Input:
- Total number of juice bottles (Must Integer)
- Number of friends (Must Integer)
Output:
- Bottles each friend gets
- Remaining bottles
Sample Input | Sample Output
17 | Each friend gets 3 bottles
5 | Remaining bottles = 2
[03]
b) A power company named "Daffodil Light Energy" supplies electricity to both residential houses and commercial buildings. Every month, customers receive a bill based on how much electricity they use. The billing system depends on following measurement.
- 0-100 units -> 5 taka per unit
- 101-200 units -> 7 taka per unit for extra units above 100
- Above 200 units -> 10 taka per unit for extra units above 200 + previous charges
Input:
- Total units consumed
Output:
- Total Bill
Sample Input | Sample Output
250 | Total bill = 1700
[03]
c) A small digital quiz system is being developed for a coding practice lab. In his system, the user enters two integers, N and K, and the system processes numbers from 1 to N one by one. For each number, it calculates its square and checks whether the square is divisible by K. If it is divisible, the system displays its square value; otherwise, it prints a message saying that "DIU CSE 71 Batch". Write a C program to implement this statement.
Input:
- Input two integers N and K.
Output:
- Print each line from 1 to N with a given statement and don't forget about the newline.
Sample Input | Sample Output
6 | DIU CSE 71 Batch
3 | DIU CSE 71 Batch
| 9
| DIU CSE 71 Batch
| DIU CSE 71 Batch
| 36
[03]
d) You are given a number N. Write a C program to print a square grid with N rows and N columns.The grid must be filled by alternating between 0 and the next positive even number (2, 4, 6, 8, ...).
Follow these simple rules:
- The very first number at the top-left must be 0.
- Keep alternating: 0, even number, 0, even number... all the way to the end.
- Every time you print an even number, increase it by 2 for the next time. Do not reset this count when you start a new row.
Input:
- Input N
Output:
- The Display Grid
Sample Input | Sample Output
5 | 0 2 0 4 0
| 6 0 8 0 10
| 0 12 0 14 0
| 16 0 18 0 20
| 0 22 0 24 0
[03]
e) A small data processing system is being developed for a coding lab. The system stores N integers in an array. The user then provides another integer K. The system checks each element of the array and selects only those numbers that are divisible by K. It then prints those divisible numbers and also calculates the average of those selected numbers. Write a C program to implement this task.
Input:
- First line two integer N and K
- Second line N integer using space separate in an array
Output:
- First line prints their average and second line prints divisible number by k.
Sample Input | Sample Output
6 3 | Average = 15.75
12 7 9 24 10 18 | Divisible numbers: 12 9 24 18
[03]