C Exercises: Level Up Your Coding
The best way to master C is through practice. Below are exercises categorized by difficulty. Try to solve them without looking at previous notes first!
Level 1: Beginner (Syntax & Logic)
Focus on basic loops, conditionals, and stdio.h.
- Exercise 1.1: Write a program that takes an integer input and checks if it is a Prime Number.
- Exercise 1.2: Create a "Temperature Converter" that converts Celsius to Fahrenheit ($F = C \times \frac{9}{5} + 32$).
- Exercise 1.3: Write a program to print the Fibonacci Series up to $n$ terms using a
for loop.
[Image of Fibonacci sequence logic flowchart]
Level 2: Intermediate (Arrays & Strings)
Focus on data manipulation and the string.h and ctype.h libraries.
- Exercise 2.1: Write a function that takes a string and checks if it is a Palindrome (reads the same backward as forward).
- Exercise 2.2: Find the Largest and Smallest element in an array of 10 integers provided by the user.
- Exercise 2.3: Write a program that counts the number of vowels, consonants, and digits in a given sentence.
Level 3: Advanced (Math & Memory)
Focus on math.h, stdlib.h, and complex logic.
- Exercise 3.1: Write a program to calculate the Standard Deviation of a set of numbers stored in an array.
- Exercise 3.2: Create a program that uses
malloc() to create a dynamic array. Ask the user for the size, fill it with numbers, and calculate the sum.
- Exercise 3.3: Implement a "Decimal to Binary" converter using bitwise operators (
& and >>).
Level 4: Real-World Challenge
The Task: Create a "Mini ATM System".
1. It should have a fixed PIN.
2. Allow the user 3 attempts to login (using ctype.h for validation).
3. Features: Check Balance, Deposit Money, and Withdraw Money.
4. Use time.h to print a receipt with the current date and time.
Technical Self-Check
| If you struggle with... |
Review this module: |
| Loop logic or Prime numbers |
C Reference / Basic Syntax |
| String comparisons or Vowels |
C String / C ctype.h |
| Memory errors or malloc |
C stdlib.h |
Pro Tip: Don't just write the code—Debug it! Use the printf() debugging method we discussed earlier to trace your variables at every step of the loop.