Summer 2025 Midterm

Back to the exam archive

Page 1

ESE124 Programming Fundamentals

Summer 2025 Midterm

Question 1

Q1: Count Characters in a File (25 pts)
Write a function that reads characters from a file called input.txt to the output.txt and counts how many are:
- letters (a-z, A-Z)
- digits (0-9)
- special characters (anything else except spaces or newlines)
Function Example:
void count_characters();
Example Input (input.txt):
C is fun! Let's learn C in 2025.
Expected Output (output.txt):
Letters: 18
Digits: 4
Special Characters: 3
Q2: Sort and Find Prime Numbers in an Array (25 pts)

Write a program that reads 10 integers from the input.txt file into an array, then sort the numbers
by using bubble sort (descendant), and put the sorted number in output.txt, then prints the prime
numbers to output.txt.

Function Examples:

int is_prime(int n);
void sort(int arr[], int length);

Example Input:

input.txt:

2 3 4 5 6 7 8 9 10 11

Expected Output:

output.txt:

Electrical and Computer Engineering | 1

Page 2

ESE124 Programming Fundamentals

Sorted: 11 10 9 8 7 6 5 4 3 2

Prime numbers: 2 3 5 7 11

Q3: Compute ln(1 + x) Using Taylor Series (25 pts)

The natural logarithm function can be approximated as:

ln(1 + x) = x - x^2/2 + x^3/3 - x^4/4 + ... (valid for -1 < x ≤ 1)

Write a function to compute ln(1 + x) using a loop.

Stop when the absolute value current term is smaller than epsilon.

Function Example:

double ln_series(double x, double epsilon);

Example Input:

User Input:

x = 0.5

epsilon = 0.0001

Expected Output:

Expected Output:

ln(1 + 0.5) ≈ 0.4055

Electrical and Computer Engineering | 2

©