C Programming Exercises

Sharpen your C skills with comprehensive topic-wise practice problems

Beginner to Advanced 150+ Problems Topic-wise Lists

Practice Makes Perfect

Master C programming through hands-on practice with our comprehensive collection of exercises. Each topic includes problems of varying difficulty levels to help you strengthen your understanding and problem-solving skills.

150+ Problems

Comprehensive coverage of all C topics

Progressive Difficulty

From beginner to advanced levels

Practical Focus

Real-world problem scenarios

1. Introduction to C, Basic Syntax and Structure

Get familiar with C program structure and basic syntax

  1. Write a program that displays "Hello, World!" on the screen. Easy
  2. Create a program that includes necessary headers, main function, and returns 0. Easy
  3. Write a program with single-line and multi-line comments explaining the code. Easy
  4. Create a program that demonstrates the basic structure of a C program. Easy
  5. Write a program that demonstrates the compilation process of a C program. Medium
  6. Create a program that shows the basic structure with multiple functions. Medium
  7. Write a program that demonstrates the use of preprocessor directives. Medium
  8. Create a program that uses standard input/output functions. Medium
  9. Write a program that demonstrates the memory layout of a C program. Hard
  10. Create a program that shows the difference between declaration and definition. Hard

2. Variables and Data Types, Constants

Practice working with different data types and constants

  1. Declare variables of different data types (int, float, double, char) and display their values. Easy
  2. Create a program that uses #define and const to declare constants and demonstrate their usage. Easy
  3. Write a program that demonstrates implicit and explicit type conversion in C. Medium
  4. Create a program that displays the size of various data types using the sizeof operator. Easy
  5. Write a program that demonstrates the use of different literals. Medium
  6. Create a program that shows the range and precision of different data types. Medium
  7. Write a program that demonstrates variable scope and lifetime. Medium
  8. Create a program that uses enumerations and shows their advantages. Medium
  9. Write a program that demonstrates the use of volatile and register keywords. Hard
  10. Create a program that shows the difference between global and local variables. Hard

3. Input and Output (I/O), Operators

Practice using I/O functions and different operators

  1. Write a program that takes user input and displays it with appropriate formatting. Easy
  2. Create a calculator program that performs basic arithmetic operations on two numbers. Easy
  3. Write a program that demonstrates the use of relational and logical operators. Easy
  4. Create a program that demonstrates the use of compound assignment operators. Easy
  5. Write a program that uses bitwise operators to manipulate data. Medium
  6. Create a program that demonstrates operator precedence and associativity. Medium
  7. Write a program that uses format specifiers for different data types. Medium
  8. Create a program that handles input validation and error checking. Medium
  9. Write a program that demonstrates the use of the conditional (ternary) operator. Hard
  10. Create a program that uses the comma operator and demonstrates its proper use cases. Hard

4. Conditional Control Statements

Practice using if, else if, else, and switch statements

  1. Write a program that checks if a number is positive using an if statement. Easy
  2. Create a program that determines the grade based on marks using if-else if-else statements. Medium
  3. Write a program that implements a simple calculator using switch case statements. Medium
  4. Create a program that uses nested if statements to solve a complex conditional problem. Hard
  5. Write a program that demonstrates the difference between if-else and switch statements. Medium
  6. Create a program that uses conditional statements to determine leap years. Medium
  7. Write a program that implements a menu-driven interface using switch cases. Medium
  8. Create a program that uses conditional operators to find the maximum of three numbers. Medium
  9. Write a program that demonstrates fall-through behavior in switch statements and how to avoid it. Hard
  10. Create a program that uses conditional statements to solve a quadratic equation. Hard

5. Loops

Practice using for, while, and do-while loops

  1. Write a program that prints numbers from 1 to 10 using a for loop. Easy
  2. Create a program that calculates the sum of numbers until the user enters 0 using a while loop. Medium
  3. Write a program that demonstrates the difference between while and do-while loops. Medium
  4. Create a program that prints patterns using nested loops (e.g., pyramid, diamond). Hard
  5. Write a program that uses loops to calculate the factorial of a number. Medium
  6. Create a program that finds prime numbers within a range using loops. Medium
  7. Write a program that demonstrates the use of break and continue statements in loops. Medium
  8. Create a program that implements the Fibonacci sequence using loops. Medium
  9. Write a program that uses loops to reverse a number. Hard
  10. Create a program that demonstrates infinite loops and how to avoid them. Hard

6. Arrays

Practice working with single and multi-dimensional arrays

  1. Write a program that declares, initializes, and displays the elements of an array. Easy
  2. Create a program that finds the sum, average, maximum, and minimum of array elements. Medium
  3. Write a program that performs matrix addition and multiplication using 2D arrays. Hard
  4. Implement sorting algorithms (bubble sort, selection sort) to sort an array of numbers. Hard
  5. Create a program that searches for an element in an array using linear and binary search. Medium
  6. Write a program that demonstrates array traversal using pointers. Medium
  7. Create a program that finds the second largest element in an array. Medium
  8. Write a program that merges two sorted arrays into a third sorted array. Hard
  9. Create a program that finds the frequency of elements in an array. Medium
  10. Write a program that implements a simple stack using arrays. Hard

7. Strings

Practice working with C-style strings

  1. Write a program that demonstrates declaration, initialization, and display of C strings. Easy
  2. Create a program that performs various string operations (concatenation, comparison, length). Medium
  3. Write a program that reverses a string, converts case, and finds substrings. Medium
  4. Create a program that checks if a given string is a palindrome. Medium
  5. Write a program that counts vowels, consonants, digits, and special characters in a string. Medium
  6. Create a program that demonstrates string manipulation without library functions. Medium
  7. Write a program that tokenizes a string using delimiters. Hard
  8. Create a program that removes all occurrences of a character from a string. Medium
  9. Write a program that checks if two strings are anagrams of each other. Hard
  10. Create a program that implements basic string encryption and decryption. Hard

8. Functions, Recursion

Practice creating functions and using recursion

  1. Write a program with functions that perform basic mathematical operations. Easy
  2. Create a program that demonstrates function prototypes and their importance. Medium
  3. Write a program that calculates factorial and Fibonacci numbers using recursion. Medium
  4. Create a program that demonstrates the use of static variables in functions. Medium
  5. Write a program that uses call by value and call by reference. Medium
  6. Create a program that demonstrates function pointers and their usage. Hard
  7. Write a program that uses recursive functions to solve the Tower of Hanoi problem. Hard
  8. Create a program that demonstrates variable-length argument lists. Hard
  9. Write a program that uses recursive functions to implement binary search. Hard
  10. Create a program that demonstrates the use of inline functions. Medium

9. Pointers, Dynamic Memory

Practice working with pointers and dynamic memory allocation

  1. Write a program that demonstrates declaration, initialization, and dereferencing of pointers. Medium
  2. Create a program that demonstrates pointer arithmetic with arrays. Medium
  3. Write a program that uses malloc, calloc, realloc, and free for dynamic memory allocation. Hard
  4. Create a program that demonstrates pointers to pointers and their usage. Hard
  5. Write a program that uses pointers to functions to implement a callback mechanism. Hard
  6. Create a program that dynamically allocates memory for a 2D array. Hard
  7. Write a program that demonstrates the use of const with pointers. Medium
  8. Create a program that implements a linked list using dynamic memory allocation. Hard
  9. Write a program that demonstrates common pointer errors and how to avoid them. Medium
  10. Create a program that uses pointers to swap values without using a temporary variable. Medium

10. Structures, Unions

Practice working with structures and unions

  1. Write a program that defines a structure to represent a student and displays its members. Medium
  2. Create a program that demonstrates arrays of structures and their manipulation. Medium
  3. Write a program that uses structures to represent complex numbers and performs operations. Medium
  4. Create a program that demonstrates nested structures. Medium
  5. Write a program that uses pointers to structures and the arrow operator. Medium
  6. Create a program that demonstrates the difference between structures and unions. Medium
  7. Write a program that uses structures to create a simple database system. Hard
  8. Create a program that demonstrates bit fields in structures. Hard
  9. Write a program that uses unions for type punning (with proper caution). Hard
  10. Create a program that demonstrates the use of typedef with structures and unions. Medium

11. File Handling

Practice working with file I/O operations

  1. Write a program that creates, writes to, and reads from a text file. Medium
  2. Create a program that copies the contents of one file to another. Medium
  3. Write a program that counts characters, words, and lines in a file. Medium
  4. Create a program that appends data to an existing file. Medium
  5. Write a program that demonstrates binary file operations (read/write structures). Hard
  6. Create a program that searches for a specific record in a file. Hard
  7. Write a program that demonstrates random access in files using fseek, ftell, and rewind. Hard
  8. Create a program that implements a simple text-based database using files. Hard
  9. Write a program that handles file errors and exceptions. Medium
  10. Create a program that merges two files into a third file. Medium

12. Advanced Topics

Practice advanced C programming concepts

  1. Write a program that demonstrates command-line arguments. Medium
  2. Create a program that uses variadic functions to calculate the average of variable numbers. Hard
  3. Write a program that implements function pointers in an array. Hard
  4. Create a program that demonstrates the use of the volatile keyword. Hard
  5. Write a program that uses bit manipulation techniques to solve problems. Hard
  6. Create a program that implements a simple state machine using function pointers. Hard
  7. Write a program that demonstrates memory alignment and padding in structures. Hard
  8. Create a program that uses setjmp and longjmp for non-local jumps. Hard
  9. Write a program that implements a simple memory allocator. Hard
  10. Create a program that demonstrates the use of inline assembly in C. Hard

Next Steps

After completing these exercises, you'll have a solid foundation in C programming. To further enhance your skills:

  • Work on larger projects that combine multiple concepts
  • Explore data structures and algorithms in C
  • Learn about multi-threading and networking in C
  • Study existing C codebases to understand real-world applications
  • Contribute to open-source C projects