C Program to Sort an Array Using Bubble Sort — With Optimisation and Complexity

Bubble Sort is the simplest sorting algorithm to understand and implement. It works by repeatedly comparing adjacent elements and swapping them if they are in the wrong order. After each pass, the largest unsorted element has “bubbled up” to its correct position at the end — just like air bubbles rising to the surface of …

Binary Search in C – Iterative and Recursive with Example

Binary search in C finds a target value in a sorted array by repeatedly halving the search space. At each step it compares the target against the middle element: if they match, the search is done; if the target is smaller, discard the right half; if larger, discard the left half. This gives O(log n) …

Decimal to Binary in C – Conversion Program with Example

Decimal to binary conversion in C uses the repeated-division-by-2 algorithm: divide the number by 2, record the remainder (0 or 1), then divide again until the quotient reaches 0. Reading the remainders from bottom to top gives the binary equivalent. This conversion is foundational for understanding how computers store integers — every value you work …

C Program to Find Largest of 3 Numbers – 3 Methods

Finding the largest of three numbers is one of the first real decisions a C program has to make. It sounds simple, but it teaches you conditional logic, how the if-else ladder works, and why wrapping repeated logic in a function pays off immediately. This post shows three approaches — a plain if-else, a ternary …

C Program to Find Array c Where c[i] = a[i] + b[n-1-i]

Given two integer arrays a[] and b[] of n elements, compute a third array c[] where each element is c[i] = a[i] + b[n-1-i]. The key insight is the index n-1-i: when i=0 it selects the last element of b, when i=n-1 it selects the first. This “reverse pairing” adds each element of a to …

C Program to Classify Triangle as Equilateral, Isosceles or Scalene

A triangle is classified by the relationship between its three sides: Equilateral — all three sides are equal (all angles are 60°) Isosceles — exactly two sides are equal (two base angles are equal) Scalene — all three sides are different (all angles are different) Before classifying, the program validates the triangle inequality: for any …