30 C Programming Basic Exercises for Intermediate with Solutions
Master intermediate 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 advanced challenges. Start your journey to C Programming mastery today!
Learning Objectives:
By the end of these exercises, you will be comfortable with intermediate concepts in C, such as pointers, arrays, dynamic memory allocation, and basic structures.
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. Write a function to check if a number is a palindrome.
Required Input:
12321
Expected Output:
12321 is a palindrome
Code In C
Output
Click Run Button to view compiled output
2. Implement a function to find the GCD of two numbers.
Required Input:
36 60
Expected Output:
GCD of 36 and 60 is 12
Code In C
Output
Click Run Button to view compiled output
3. Write a function to sort an array {5, 3, 8, 6, 2} in ascending order.
Required Input:
5 3 8 6 2
Expected Output:
Sorted array: 2 3 5 6 8
Code In C
Output
Click Run Button to view compiled output
4. Implement a function to reverse a string "programming".
Required Input:
programming
Expected Output:
Reversed string: gnimmargorp
Code In C
Output
Click Run Button to view compiled output
5. Write a function to calculate the factorial of a number (6) using recursion.
Required Input:
6
Expected Output:
Factorial of 6 is 720
Code In C
Output
Click Run Button to view compiled output
6. Write a function to find the minimum element in an array {3, 5, 2, 8, 1}.
Required Input:
3 5 2 8 1
Expected Output:
Minimum element: 1
Code In C
Output
Click Run Button to view compiled output
7. Print the first 10 elements of the Fibonacci sequence.
Required Input:
10
Expected Output:
0 1 1 2 3 5 8 13 21 34
Code In C
Output
Click Run Button to view compiled output
8. Count the number of words in a string "C programming is fun".
Required Input:
C programming is fun
Expected Output:
Number of words: 4
Code In C
Output
Click Run Button to view compiled output
9. Write a function to find the second largest element in an array {12, 35, 1, 10, 34, 1}.
Required Input:
12 35 1 10 34 1
Expected Output:
Second largest element: 34
Code In C
Output
Click Run Button to view compiled output
10. Calculate the sum of the diagonal elements in a 3x3 matrix.
Required Input:
Matrix:
1 2 3
4 5 6
7 8 9
Expected Output:
Sum of diagonal elements: 15
Code In C
Output
Click Run Button to view compiled output