C program examples
Small programs you can understand, run, and change. Each example includes its logic, sample output, and the concepts to watch.
“Try in Circuit” opens a new saved copy. Your existing programs stay intact. Interactive examples accept input in the terminal; sample responses shown on each page are for you to enter.
Basic Programs
Conditions
Loops
Factorial
Multiply a sequence of integers with a bounded loop and handle zero factorial.
View code and explanation →Fibonacci Sequence
Generate Fibonacci numbers by retaining only the previous two values.
View code and explanation →Prime Number
Determine primality using trial division and a safe stopping condition.
View code and explanation →Reverse a Number
Extract decimal digits from a nonnegative integer and rebuild them in reverse order.
View code and explanation →Palindrome Number
Compare a number with its reversed digits to recognize numeric palindromes.
View code and explanation →Multiplication Table
Read three inputs in sequence and print a chosen range of multiplication facts.
View code and explanation →Functions
Arrays
Array Sum
Walk through a fixed array and accumulate its values without stepping past its bounds.
View code and explanation →Reverse an Array
Reverse an array in place by swapping pairs from opposite ends.
View code and explanation →Matrix Addition
Add corresponding entries of two small matrices using nested loops.
View code and explanation →