Codes & Snippets
Explore our collection of useful algorithms, patterns, and boilerplates.
Description
Calculates the properties of a square: Area (A), Perimeter (P), and Diagonal (D) based on side length.
Description
Calculates the Area and Volume of a cylinder given radius (r) and height (h).
Description
Calculates distance (s) using the equation of motion s = ut + ½at² over a time range.
Description
Performs basic arithmetic operations (+, -, /, %) based on user input using a switch case.
Description
Calculates the sum of individual digits of a given positive integer.
Description
Generates the Fibonacci series up to a specified number of terms.
Description
Finds prime numbers within a given interval.
Description
Calculates the sum of the series: 1 - X^2/2! + X^4/4! ...
Description
Calculates the area, perimeter, and diagonal of a rectangle.
Description
Reverses each individual word in a given string.
Description
Reads multiple lines of input until a semicolon and calculates their lengths.
Description
Converts a Roman numeral string to its decimal integer equivalent.
Description
Calculates the Greatest Common Divisor (GCD) of two numbers using both recursive and non-recursive methods.
Description
Finds the roots of a quadratic equation and handles real, equal, and imaginary roots.
Description
Finds the largest and smallest elements in a user-input integer array.
Description
Demonstrates dynamic memory allocation and resizing of an array using malloc and realloc.
Description
Manages a dynamic 2D array (matrix) allowing the user to increase or decrease the number of rows.
Description
Performs arithmetic operations using preprocessor #define macros.
Description
Determines if a given number is prime. Optimized solution checking up to square root.
Description
Finds the index where a target value should be inserted in a sorted array using Binary Search.
Description
Greedy algorithm to distribute minimum candies ensuring children with higher ratings get more than neighbors.
Description
Finds the largest minimum distance to place cows in stalls using Binary Search on the answer.
Description
Detects if a cycle exists in an undirected graph using Depth First Search (DFS).
Description
Finds all critical connections (bridges) in a network using Tarjan's Bridge-Finding Algorithm.
Description
Counts the number of islands in a grid where '1' is land and '0' is water using DFS.
Description
Uses BFS to find the minimum time required to rot all oranges in a grid.
Description
Calculates the minimum number of operations required to convert string A to string B using Dynamic Programming.
Description
Finds the path from top left to bottom right in a grid with minimum sum.
Description
Removes K digits from a number to form the smallest possible number.
Description
Calculates the number of unique paths in a grid from top-left to bottom-right.