Appendix E: Projects & Practice
Hands-on C projects and coding challenges for practice.
Appendix E: Projects & Practice
Table of Contents
E.1 Mini Projects
- Calculator: Build a simple calculator supporting +, -, *, / operations.
- Student Database: Create a program to store and search student records.
- File Copier: Write a program to copy contents from one file to another.
E.2 Practice Challenges
- Reverse the words in a sentence.
- Count the frequency of each character in a string.
- Implement a basic stack using arrays.
E.3 Exercises
- Write a program to check if a number is prime.
- Implement a function to sort an array of integers.
- Write a program to find the largest element in a 2D array.
E.4 Solutions
E.4.1 Solution 1
1
2
3
4
5
6
int is_prime(int n) {
if (n < 2) return 0;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
return 1;
}
E.4.2 Solution 2
1
2
3
4
5
6
7
void sort(int arr[], int n) {
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1]) {
int t = arr[j]; arr[j] = arr[j+1]; arr[j+1] = t;
}
}
E.4.3 Solution 3
1
2
3
4
5
6
7
int max2D(int arr[][N], int rows, int cols) {
int max = arr[0][0];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
if (arr[i][j] > max) max = arr[i][j];
return max;
}
This post is licensed under CC BY 4.0 by the author.