C Programming Examples
Explore our collection of C programming examples and code snippets. Learn by doing with practical examples you can run directly in our online compiler.
Basic Programs
15 examplesEssential C programs for beginners
Hello WorldCalculatorPrime Number Check+2 more
Loops and Control Flow
12 examplesPrograms demonstrating loops and conditional statements
For LoopWhile LoopDo-While Loop+2 more
Functions and Recursion
10 examplesFunction definitions, calls, and recursive programming
Function BasicsRecursive FunctionsFunction Pointers+2 more
Arrays and Strings
18 examplesWorking with arrays, strings, and character manipulation
Array OperationsString FunctionsCharacter Arrays+2 more
Data Structures
8 examplesImplementation of common data structures in C
Linked ListsStacksQueues+2 more
Algorithms
14 examplesCommon algorithms and sorting techniques
Bubble SortQuick SortBinary Search+2 more
Featured Examples
Hello World Program
The classic first program in C programming.
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}Fibonacci Series
Generate Fibonacci series up to n terms.
#include <stdio.h>
int main() {
int n, first = 0, second = 1, next;
printf("Enter number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (int i = 0; i < n; i++) {
if (i <= 1)
next = i;
else {
next = first + second;
first = second;
second = next;
}
printf("%d ", next);
}
printf("\n");
return 0;
}Bubble Sort
Sort an array using bubble sort algorithm.
#include <stdio.h>
void bubbleSort(int arr[], int n) {
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main() {
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr)/sizeof(arr[0]);
printf("Original array: ");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
bubbleSort(arr, n);
printf("Sorted array: ");
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
return 0;
}Ready to Start Coding?
All examples are ready to run in our online C compiler. No setup required!
Open Online C Compiler