Category Archives: C Programs

GCD of two numbers is the largest number that divides both of them. A simple way to find GCD is to factorize both numbers and… Read More
Following is a typical recursive implementation of Merge Sort that uses last element as pivot. /* Recursive C program for merge sort */ #include <stdio.h>… Read More
Given two sorted arrays and a number x, find the pair whose sum is closest to x and the pair has an element from each… Read More
There are n stairs and a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2… Read More
We can use binary search to reduce the number of comparisons in normal insertion sort. Binary Insertion Sort find use binary search to find the… Read More
Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] and its permutations (or… Read More
Given a positive integer N, count all possible distinct binary strings of length N such that there are no consecutive 1’s. Examples: Input: N =… Read More
Area of a circle can simply be evaluated using following formula.  Area = pi * r2 where r is radius of circle C #include <math.h>… Read More
Transpose of a matrix is obtained by changing rows to columns and columns to rows. In other words, transpose of A[][] is obtained by changing… Read More
Factorial of a non-negative integer is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is… Read More
Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire… Read More
Given an array, find the largest element in it. Input : arr[] = {10, 20, 4} Output : 20 Input : arr[] = {20, 10,… Read More
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples : Input: n = 5 Output: 1 Factorial of… Read More
Catalan numbers are a sequence of natural numbers that occurs in many interesting counting problems like following. 1) Count the number of expressions containing n… Read More
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. C/C++ // C program… Read More