30 C Programming Basic Exercises for Advanced with Solutions
Master advanced C Programming skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in C Programming, setting a solid foundation for professional-level challenges. Start your journey to C Programming mastery today!
Learning Objectives:
By the end of these exercises, you will have mastered advanced C concepts, including file handling, complex data structures, multi-file projects, and performance optimization techniques.
Exercise Instructions:
- Start with the first exercise and attempt to solve it before checking the hint or solution.
- Ensure you understand the logic behind each solution, as this will help you in more complex problems.
- Use these exercises to reinforce your learning and identify areas that may require further study.
1. Implement a program to create a dynamic array and calculate its average.
Required Input:
size = 5, elements = {10, 20, 30, 40, 50}
Expected Output:
Average = 30.00
Code In C
Output
Click Run Button to view compiled output
2. Create a program to store student records using a struct and display the details.
Required Input:
Student = {name = 'Alice', age = 21, grade = 'A'}
Expected Output:
Name: Alice, Age: 21, Grade: A
Code In C
Output
Click Run Button to view compiled output
3. Implement a union to store either an integer or a float and display the value based on the type chosen.
Required Input:
choice = 'i', value = 10
Expected Output:
Integer Value: 10
Code In C
Output
Click Run Button to view compiled output
4. Write a program to handle exceptions using setjmp and longjmp for error handling in C.
Required Input:
dividend = 10, divisor = 0
Expected Output:
Error: Division by zero
Code In C
Output
Click Run Button to view compiled output
5. Create a linked list to store and display the elements.
Required Input:
elements = {5, 10, 15}
Expected Output:
5 -> 10 -> 15
Code In C
Output
Click Run Button to view compiled output
6. Write a program to perform matrix multiplication.
Required Input:
A = {{1, 2}, {3, 4}}, B = {{5, 6}, {7, 8}}
Expected Output:
Result Matrix:
19 22
43 50
Code In C
Output
Click Run Button to view compiled output
7. Implement a program to find the maximum element in an array using pointers.
Required Input:
arr = {5, 3, 8, 1, 4}
Expected Output:
Maximum Element = 8
Code In C
Output
Click Run Button to view compiled output
8. Write a program to implement a simple stack using an array and perform push and pop operations.
Required Input:
push(10), push(20), pop()
Expected Output:
Popped Element = 20
Code In C
Output
Click Run Button to view compiled output
9. Implement a function to sort an array of integers using the Quick Sort algorithm.
Required Input:
arr = {5, 3, 8, 1, 4}
Expected Output:
Sorted Array: 1 3 4 5 8
Code In C
Output
Click Run Button to view compiled output
10. Create a program to merge two sorted arrays into a single sorted array.
Required Input:
A = {1, 3, 5}, B = {2, 4, 6}
Expected Output:
Merged Array: 1 2 3 4 5 6
Code In C
Output
Click Run Button to view compiled output