C Example Programs
Master C programming by writing and running practical code. Browse our categorized collection of tested C programs covering essential loops, arrays, pointer algorithms, matrix computations, sorting routines, and foundational data structures.
Area of Shapes Program in C — Geometric Calculations
Calculate the area of geometric shapes (circle, triangle, rectangle, sphere) in C using functions, mathematical constants, and standard math.h.
ASCII Value Program in C — Character Code Inspector
Print ASCII values of characters, numbers, and symbols in C using format specifiers. Explore ASCII conversion tables and character arithmetic.
String to Integer (atoi) in C — Custom Implementation
Implement your own atoi (ASCII to Integer) function in C from scratch. Handle leading whitespace, positive/negative signs, and integer overflow.
Binary Tree Traversal in C — Preorder, Inorder, Postorder
Implement Binary Tree traversals in C: Inorder, Preorder, and Postorder using recursive depth-first algorithms with full C source code.
Circular Queue in C — Array Implementation with Modulo
Implement a Circular Queue in C using modulo arithmetic to prevent memory wastage. Complete code for circular enqueue, dequeue, and display.
Command Line Arguments in C — argc and argv Guide
Learn how to parse command line arguments in C using argc and argv. Complete working code for flag parsing, option switches, and type casting.
File Handling Read & Write in C — fopen, fread, fwrite
Master text and binary file I/O operations in C using fopen, fprintf, fscanf, fread, and fwrite with error handling and buffer flushing.
Function Pointers in C — Callback & Dispatcher Guide
Master function pointers in C with syntax rules, callback function handlers, comparator sorting, and jump tables with full runnable code.
Integer to String (itoa) in C — Custom Implementation
Convert integers to character strings in standard C without non-standard itoa. Full working code for arbitrary bases, signs, and buffer safety.
Number Pattern Programs in C — Triangle, Floyd & Matrix
Master number patterns in C including Floyd's triangle, continuous number pyramids, and binary alternating grids with runnable C programs.
Perfect Number in C — Proper Divisor Sum Algorithm
Check if an integer is a perfect number in C by summing its proper divisors. Optimized O(sqrt(n)) algorithm with working source code.
Sieve of Eratosthenes in C — Prime Generator Algorithm
Generate prime numbers up to N efficiently in C using the Sieve of Eratosthenes. Full working code, boolean array sieve, and O(n log log n) trace.
Stack Using Linked List in C — Dynamic Push & Pop
Implement a dynamic stack data structure in C using singly linked list nodes. Complete code for push, pop, peek, and heap memory management.
Star Pattern Programs in C — Pyramid, Diamond & Triangle
Learn how to print star patterns in C: right-angled triangle, inverted pyramid, and diamond shapes using nested loops with full code.
Static vs Global Variables in C — Scope & Lifetime Guide
Understand static vs global variables in C: file scope vs internal linkage, stack vs data segment memory, lifetimes, and storage classes.
Strong Number in C — Factorial Sum of Digits Program
Learn how to check if a number is a Strong (Krishnamurthy) number in C by calculating the sum of factorials of digits with complete code.
Structures and Unions in C — Memory Allocation & Syntax
Master the difference between structs and unions in C with memory layout diagrams, byte alignment, sizeof demonstrations, and working examples.
Temperature Conversion in C — Celsius, Fahrenheit & Kelvin
Build a temperature conversion program in C to convert between Celsius, Fahrenheit, and Kelvin using precise floating-point formulas.
Armstrong Number in C — Check & Print Narcissistic Numbers
Learn how to check if a number is an Armstrong (narcissistic) number in C for any number of digits with full working code and complexity analysis.
Binary Search in C — Iterative & Recursive Approaches
Implement Binary Search in C on sorted arrays. Iterative and recursive algorithms explained with mid-point calculations and overflow prevention.
Count Vowels and Consonants in C — String Parser
Write a C program to count vowels, consonants, digits, and whitespace in a string using standard ctype.h classification functions.
Dynamic Memory Allocation in C — malloc, calloc & free
Master dynamic heap memory allocation in C with malloc, calloc, realloc, and free. Step-by-step memory safety and leak prevention guide.
Factorial Program in C — Iterative & Recursive Logic
Compute the factorial of a number in C using iterative loops and recursive functions. Full code, step trace, and overflow handling explained.
GCD and LCM in C — Euclidean Algorithm & Formulas
Calculate Greatest Common Divisor (GCD) and Least Common Multiple (LCM) in C using Euclidean algorithm and modular arithmetic with examples.
Insertion Sort in C — Algorithm, Code & Trace
Learn Insertion Sort in C with step-by-step element insertion trace, full runnable source code, and time complexity comparison explained.
Leap Year Program in C — Gregorian Calendar Rules
Check whether a given year is a leap year in C using Gregorian calendar conditional logic with multiple approaches and test examples.
Linear Search in C — Algorithm, Code & Time Complexity
Implement Linear Search in C for unsorted arrays. Step-by-step element search trace, best/worst case comparisons, and sample code included.
Matrix Addition in C — 2D Array Arithmetic Guide
Add two matrices in C using 2D arrays and nested loops. Includes dimension checks, code implementation, and element-wise addition trace.
Merge Sort in C — Divide & Conquer Algorithm Guide
Learn Merge Sort in C with recursive splitting, array merging logic, full working source code, and guaranteed O(n log n) complexity.
Pascal's Triangle in C — Combinations & Array Logic
Print Pascal's Triangle in C using binomial combinations formula and 2D dynamic arrays. Step-by-step coefficient calculations explained.
Queue Implementation in C Using Array — Enqueue & Dequeue
Implement a FIFO Queue data structure in C using fixed arrays. Complete code for enqueue, dequeue, peek, and capacity overflow management.
Quicksort in C — Divide & Conquer Algorithm Guide
Implement Quicksort in C using Lomuto partitioning. Includes recursion stack trace, pivot selection strategies, and complexity analysis.
Remove Duplicates from String in C — Fast Frequency Hash
Remove duplicate characters from a string in C using a frequency hash map and two pointers with O(n) linear time complexity.
Reverse a Number in C — Integer & Pointer Methods
Reverse an integer in C with full source code, step-by-step logic, negative number handling, and integer overflow protection explained.
Selection Sort in C — Algorithm, Code & Trace
Implement Selection Sort in C with step-by-step logic, code, array swapping with pointers, and full time and space complexity breakdown.
Simple Calculator in C — Switch Case & Arithmetic
Build a command-line calculator in C using switch-case statements, arithmetic operators, division-by-zero checks, and modular functions.
Singly Linked List in C — Insert, Delete & Traverse
Implement a Singly Linked List in C with dynamic memory allocation (malloc/free). Full code for node insertion, deletion, and traversal.
Stack Implementation in C Using Array — Push & Pop
Implement a Stack data structure in C using static arrays. Complete runnable code for push, pop, peek, isFull, and isEmpty operations.
Reverse a String in C — Pointer & In-Place Methods
Reverse a character string in C in-place using two-pointer swapping and without using strrev. Full working code and memory safety explained.
Sum of Digits in C — Iterative & Recursive Programs
Calculate the sum of digits of an integer in C using loops and recursion. Step-by-step trace, edge cases, and code examples explained.
Tower of Hanoi in C — Recursion Algorithm & Trace
Solve the classic Tower of Hanoi puzzle in C with recursive algorithms, disk move tracing, step counts, and 2^n - 1 complexity explained.
Transpose of a Matrix in C — 2D Array Transformation
Compute the transpose of a matrix in C by swapping row and column indices. Complete runnable C code and square matrix in-place swap logic.
Bubble Sort in C — Algorithm & Optimized Code
Implement Bubble Sort in C with optimized early exit flags. Includes step-by-step trace, memory comparisons, and time complexity analysis.
Fibonacci Series in C — Iterative & Recursive Code
Generate the Fibonacci series in C using iterative loops and recursive functions. Complete code with complexity analysis and output.
Matrix Multiplication in C — 2D Array Algorithm
Multiply two matrices in C using 2D arrays and nested loops. Complete validated source code, dimension validation rules, and complexity breakdown.
Palindrome Program in C — String & Number Check
Check if a number or string is a palindrome in C with complete tested code, step-by-step arithmetic trace, and string pointer examples.
Prime Number Program in C — Optimized Algorithm
Check if a number is prime and print prime numbers in a range in C using optimized sqrt(n) algorithms with complete source code.
Swap Two Numbers in C — Pointers & Bitwise Methods
Learn how to swap two numbers in C using temporary variables, arithmetic operations, bitwise XOR, and pass-by-reference pointers.