C Program to Calculate Volume and Total Surface Area of Sphere

Here is a C program to find total surface area and volume of a sphere. A sphere is a three dimensional object such that all points on sphere are located at a distance R (radius of sphere) from a given point (center of sphere). A sphere is perfectly symmetrical and has no edges or vertices. Spheres are very common in everyday life, like soccer ball, ball bearings etc. Spheres are very common in nature, whenever an object wants to reduce it's surface area as much as possible without reducing volume, like water drops.

C Program to Calculate Volume and Total Surface Area of Cylinder

In this C program we will calculate total surface area and volume of a cylinder. A cylinder is a three dimensional solid that has two circular bases connected by a curved surface. A cylinder can be formed by two circles of same radius(R) and the curved surface formed by all the points at a distance of R from axis(axis is a line segment joining the center of both bases). Cylinder objects are very common in everyday life, like a cylindrical can.

C Program to Calculate Volume and Total Surface Area of Cone

Here is the C program to find total surface area and volume of a cone. A cone is an three-dimensional geometric shape having circular base and only one vertex. A cone can be formed by the locus of all straight line segments that join the vertex to the base has a rotational symmetry. We can say that a cone have flat circular base and having one side curved surface. The volume and the total surface area of the cone depend upon the radius of base, height and slant height of the cone.

C Program to Calculate Volume and Total Surface Area of Cuboid

Here is a C program to calculate total surface area and volume of a cuboid. A cuboid is a three dimensional object having six rectangular sides. A cuboid has twelve edges, six rectangular faces and eight vertices. This type of cuboid is also known as a rectangular cuboid or right cuboid.

Each face of a cuboid is a rectangle and angle between all three adjacent rectangular faces are 90.. Opposite faces of a cuboid are parallel and identical. The cube is a special case of the square cuboid in which all six faces are squares.

For Example : A brick is a cuboid.

C Program to Calculate Volume and Total Surface Area of Cube

In this C program, we will find total surface area and volume of a cube. A cube is a three dimensional object having equal width, height, and length measurements. A cube has twelve edges, six square faces and eight vertices. The cube can also be called a regular hexahedron.
Each face of a cube is a square of same side length and angle between all adjacent faces are 90.. At each vertex, three square faces of cube meet at right angle.
For Example : A dice is a cube.

C Program to Calculate Area of Any Triangle using Heron's Formula

Here is a C program to find the area of a triangle using Heron's Formula. If we know the length of all sides of any triangle, then we can calculate the area of triangle using Heron's Formula. Heron's formula is a generic formula and is not specific to any triangle, it can be used it find area of any triangle whether it is right triangle, equilateral triangle or scalene triangle. Heron's formula relates the side lengths, perimeter and area of a triangle.

Heron's formula(also known as Hero's formula) is named after Hero of Alexandria a Greek Engineer and Mathematician. Heron was a great mathematicians of his time and came up with this formula in the first century BC. He also expanded the scope of this formula to calculate the area of quadrilaterals and polygons.

C Program to Calculate Area of an Equilateral Triangle

Here is a C program to find the area and permimeter of an equilateral triangle. An equilateral triangle is a triangle in which all three sides and angles are equal. All three internal angles of equilateral triangle measures 60 degree.

C Program to Calculate Area of a Right Angled Triangle

Here is a C program to find the area of a right angled triangle. Right-angled triangle is a triangle in which one angle is a right angle (90 degree). The sum of the other two angles of right-angled triangle is 90 degree. The relation between sides and angles of right angled triangle is the foundation of trigonometry and pythagoras theorem.

A branch of mathematics, known as trigonometry is based on right triangles. Most of the properties and formula of trigonometry is based on ratio and proportions of sides and angles of right triangle like Sine, Cosine, Tangent etc.

C Program to Calculate Area and Perimeter of Trapezium

Here is a C program to find the area and perimeter of a trapezium(trapezoid). A trapezium is a quadrilateral with at least one pair of parallel sides, other two sides may not be parallel. The parallel sides are called the bases of the trapezium and the other two sides are called it's legs. The perpendicular distance between parallel sides is called height of trapezium.

In North America, A trapezium is referred to as a trapezoid.

C Program to Calculate Area and Perimeter of a Rhombus

Here is a C program to find the area and perimeter of a rhombus. A rhombus is quadrilaterals(having four sides) with all sides equal in length and opposites sides parallel. Opposite angles of a rhombus are also equal. A rhombus is a special case of parallelogram where all sides are equal in length.

C Program to Calculate Area and Perimeter of a Square

Here is a C program to find the area and perimeter of a square. A square is quadrilaterals(having four sides) having all sides equal and all interior angles are 90.(right angles). Opposite sides of a square are parallel. A square is a special case of parallelogram where all sides and internal angles are equal.

The area of a square is the amount of two-dimensional space inside the boundary on square. The area of a square can be calculated by placing a square shape object over a grid and counting the number of square units it takes to completely fill a square.

The perimeter of a square is the linear distance around the boundary of the square.
In other words, we can think of perimeter of a square surface as the length of fence needed to enclose that square surface, whereas area is the space inside square surface. Perimeter is measured in linear units whereas area is measured in square units.

C Program to Calculate Area and Perimeter of Parallelogram

Here is a C program to find the area and perimeter of a parallelogram. A parallelogram is quadrilaterals(having four sides) with opposite sides parallel and equal in length. Opposite angles of a parallelogram are also equal.

The area of parallelogram is the amount of two-dimensional space inside it's boundary. The area of a parallelogram can be calculated by placing the parallelogram over a grid and counting the number of square units it takes to completely fill a parallelogram.

C Program to Calculate Area and Perimeter of a Rectangle

Here is a C program to find the area and perimeter of a rectangle. The rectangle is quadrilaterals(having four sides). All four interior angles of a rectangle are 90.(right angles).
The area of a rectangle is the amount of two-dimensional space inside the boundary on rectangle. The area of a rectangle can be calculated by placing the rectangle over a grid and counting the number of square units it takes to completely fill a rectangle.

The perimeter of a rectangle is the linear distance around the boundary of the rectangle.
In other words, we can think of perimeter of a rectangular surface as the length of fence needed to enclose that rectangular surface, area is the space inside surface. Perimeter is measured in linear units like meter, centimeter, mile etc, whereas area is measured in square units like cm2, Km2 etc.

C Program to Calculate Area of a Circle

Here is a C program to find the area and circumference of a circle. A circle is a simple geometrical shape. A circle is a set of all points in a 2D plane that are at a given distance from a given point called centre. A circle can be uniquely identified by it's center co-ordinates and radius.

C Program to Reverse a Number Using Recursion

Here is a C program to reverse digits of a number using recursion. Reversing the digits of a number means reversing the sequence of digits in a number. After reversing, least significant digit will become most significant digit of number and most significant digit becomes least significant digit and so on.

Let the total number of digits in a number is N. So a digit at ith position from left will become ith digit from right or N-i+1th digit from left.

For Example

Befor reverse : 25346
After reverse : 64352

C Program to Find Factorial of a Number using Recursion

Here is a C program to calculate factorial of a number using recursion. The factorial of a integer N, denoted by N! is the product of all positive integers less than or equal to n. Factorial does not exist for negative numbers and factorial of 0 is 1.

N! = 1 x 2 x 3 x 4....x (N-2) x (N-1) x N

C Program to Find Sum of Digits of a Number using Recursion

Here is a C program to find sum of digits of a number using recursion. To find the sum of digits of a number, we have to add the each digit of a number. Here, to find the sum of digits of a number we will remove one digit at a time from a number and add it to a variable.

For Example
Sum of digits of 4265 = 4 + 2 + 6 + 5 = 17

To extract digits of a number we can use '/'(division) and '%'(modulus) operator. Number%10 will give the least significant digit of the Number, we will use it to get one digit of number at a time. To remove last least significant digit from number we will divide number by 10. We can use recursion to implement above mentioned algorithms because it can be expressed as recursive equation.

C Program to Find Power of a Number using Recursion

Here is a C program to find power of a number(ab) using recursion. The power of a number(baseexponent)is the base multiplied to itself exponent times.

For Example
ab = a x a x a .....x a(b times)
24 = 2x2x2x2 = 16

C Program to Find Sum of Array Elements using Recursion

Here is a C program to find the sum of elements of array using recursion. We will first take N numbers as input from user using scanf function and store it in an integer array. Now, we have to find sum of all elements of array from index 0 to N-1 using recursion.

For Example

Input Array : 1 2 3 4 5
Sum of Array Element : 15

C Program to Reverse a String using Recursion

Here is a C program to reverse a string using recursion. To reverse a string, we have to reverse the sequence the characters of string. First character of original string should become last character in reversed string, second character of original string should become second last character of reversed string and so on.

For Example
Input: CProgramming
Output (Reversed String): gnimmargorPC

To reverse a string of length N using recursion, we have to swap the leftmost and rightmost characters of a string and then recursively reverse the inner sub-string from index 1 to N-2. Keep on repeating this unless size of sub-string is greater than one.

C Program for Palindrome Check using Recursion

Here is a C program to check if a string is palindrome or not using recursion. A string is palindrome, if string remains same after reversing sequence of it's character. For example, "tenet" is a palindrome string whereas "mango" is not a palindrome string.

We can check whether a string is palindrome or not using recursion by breaking this problem into a smaller problem.

C Program to Print Fibonacci Series using Recursion

IN this C program, we will learn about generating fibonacci series using recursion. Fibonacci series are the numbers in the following integer sequence
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ....
the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent term is the sum of the previous two terms. In mathematical terms, the Nth term of Fibonacci numbers is defined by the recurrence relation:

C Program to Reverse an Array Using Recursion

Here is a C program to reverse an array by swapping elements and recursion. To Reverse an array we have to reverse the sequence of array elements. The first element of array should become the last element and last element will become the first element.

For Example:
If Input array is : 1 2 3 4 5 6 7
Reversed array should be : 7 6 5 4 3 2 1

To reverse an array of length N using recursion, we have to swap the leftmost(array[0]) and rightmost(array[N-1]) element of array and then recursively reverse the inner sub-array from index 1 to N-2. Keep on repeating this unless size of sub-array is greater than one.

C Program to Delete Duplicate Elements from a Sorted Array

Here is the C program to delete duplicate elements from a sorted array. Given a sorted integer array of length N. Array elements are sorted in increasing order(inputArray[i] <= inputArray[j] for every i < j). We have to delete duplicate elements from array and print unique elements of the array.

For Example
Sorted array containing duplicate elements : 1 2 2 2 4 4 7 8 9 9
Output array containing only unique elements : 1 2 4 7 8 9

C Program to Delete Duplicate Elements from an Array

Here is the C program to delete duplicate elements from an unsorted array. Given an array of length N, which may contain some duplicate elements. We have to remove all duplicate elements and print only unique elements in array. If an element is present more than once in input array then output array should contain only one one instance of that element.

For Example

Input Array: 6 3 3 5 8 6
Output Array: 6 3 5 8

C Program to Find Second Largest Element in Array

Here is the C program to find the second largest element in an unsorted array. Given an array of integers of length N, we have to find the second largest element in array without sorting the array.

For Example
Let inputArray is an integer array of seven elements.
int inputArray[7] = {2, -3, 0, 5, 9, 13, 1};
Second largest element of inputArray is 9

C Program to Reverse an Array

Here is the C program to reverse an array with and without using temporary array. Given an array of integers of length N, we have to reverse the sequence of array elements. The first element of array should become the last element and vice versa.

For Example

If input array is : 1 2 3 4 5 6 7
Reversed array should be : 7 6 5 4 3 2 1,

The algorithm to reverse an array is similar to the algorithm of reversing a string. Actually, a string is also an array of characters. We can reverse an array either by using a temporary array of same size or without using any extra memory by swapping elements.

C Program to Delete an Element from an Array

Here is the C program to delete an element from an array. Given an array of length N, we have to delete an element at index i (0 <= i <= N-1) from an array. After deleting an element, the number of elements in array will decrease by one.

All elements of array are stored in contiguous memory location. To delete an element at index i in array we have to shift all elements from index i+1 to N-1 to previous index. An element at index k, will be moved to index k-1.

For Example

Suppose we have an array "inputArray" of length 9, which contains 6 elements from inputArray[0] to inputArray[5]. We have to delete element at index 2. Move every element from inputArray[3] to inputArray[5] to previous index in array.
Move inputArray[3] to inputArray[3],
Move inputArray[4] to inputArray[3],
Move inputArray[5] to inputArray[4].
This will delete inputArray[2] by overwriting it with inputArray[4].
Now total number of elements in inputArray becomes 5 from index 0 to 4.

C Program to Insert an Element in Array

Here is a C program to insert an element in an array at given position. Given an array of length N, we have to insert an element in array at index i (0 <= i <= N-1). After inserting an element, the number of elements in array will increase by one.

All elements of array are stored in consecutive memory location. To insert an element at index i in array we have to shift all elements from index i to N-1 to next index. An element at index k, will be moved to index k+1.

For Example

Suppose we have an array "inputArray" of length 10, which contains 7 elements from inputArray[0] to inputArray[6]. We have to insert 15 at position inputArray[3].
Move every element from inputArray[3] to inputArray[6] to next index in array.
Move inputArray[6] to inputArray[7],
Move inputArray[5] to inputArray[6],
Move inputArray[4] to inputArray[5],
Move inputArray[3] to inputArray[4].
Now, insert 15 at inputArray[3].

C Program to Find Smallest Element in an Array

In this C program, we will learn about finding smallest element of an array. Given an array of length N, we have to find the minimum element of an array and it's position in array.

If minimum element occurs more than once in input array, then we will return the index of it's first occurrence(smallest index). We can find the minimum element in an array by traversing the array from first to last element and comparing each element with the minimum element found till now.

C Program to Find the Largest Element in an Array

In this C program, we will learn about finding largest element of an array. Given an array of length N, we have to find the maximum element in array and it's position in array.

We can find the maximum element in an array by traversing the array from index 0 to N-1 and comparing each element with the maximum element found till now using comparison operators.

C Program to Find Sum Each Row and Column of Matrix

Here is the C program to calculate the sum of each row and columns of matrix. Given a matrix A of size mxn, we have to calculate the sum of elements of each rows and columns of matrix. we will use one array of length m to store sum of elements of each row and an array of length n to store sum of elements of each column.

C Program for Matrix Multiplication

Here is the C program for matrix multiplication. We have to take two matrix as input form user and multiply them to get product of two input matrices. We can multiply two matrices only if the number of columns of the 1st matrix must equal the number of rows of the 2nd matrix.

C Program to Print a Matrix Diagonally

Here is the C program to print a matrix diagonally from top to bottom. Given a matrix of size m x n, we have to print the matrix diagonally from right to left and top to bottom. We have to print one diagonal in a separate line.

The minor diagonal divides a matrix into two parts, elements above minor diagonal(upper half) and elements below minor diagonal(lower half). In below mentioned C program, we first print upper half of matrix then lower half of matrix diagonally.

C Program to Check Identity Matrix

Here is the C program to check whether a given matrix is an Identity matrix or not. Identity matrix is a square matrix with ones on the main diagonal and zeros elsewhere. An identity matrix is denoted I and an Identity matrix of size n is a n x n square matrix and is denoted by In.

C Program to Compare Two Matrix

Here is a C program to check if two given matrices are equal or not. This C program takes two matrices as input from user and compares them for equality. If both matrices are equal, it will print "EQUAL MATRICES" on screen otherwise "UNEQUAL MATRICES".

C Program to Print Upper Triangular Matrix

Here is the C program to print upper triangular matrix of a square matrix. The main diagonal of a square matrix divides it into two sections, one above the diagonal and the other one is below the diagonal. If all elements in lower-section consists of zeros, it is a upper-triangular matrix and If all elements in upper-block consists of zeros, it is a lower-triangular matrix.

An upper triangular matrix is a square matrix in which all the elements below the main diagonal are zero. The variable U is commonly used to represent a upper triangular matrix.

C Program to Print Lower Triangular Matrix

Here is the C program to print lower triangular matrix of a square matrix. The main diagonal of a square matrix divides it into two sections, one above the diagonal and the other one is below the diagonal.

If all elements in lower-section consists of zeros, it is a upper-triangular matrix and If all elements in upper-block consists of zeros, it is a lower-triangular matrix.
A lower triangular matrix is a square matrix in which all the elements above the main diagonal are zero. The variable L is commonly used to represent a lower triangular matrix.

C Program to Find Scalar Multiplication of a Matrix

Here is the C program for scalar multiplication of a matrix. There are two kinds of matrix multiplication, scalar multiplication and matrix multiplication.

Matrix multiplication is multiplication of two matrices whereas scalar multiplication is multiplication of a matrix and a single number.

C Program to Find Sum of Diagonal Elements of Matrix

Here is the C program to find sum of diagonal elements of a matrix. An element A[i][j] of matrix A is said to be diagonal element, if i == j.

For a matrix A of size 3 X 3, A[0][0], A[1][1] and A[2][2] are diagonal elements of A. Given a matrix of size M x N, we have to find the sum of all diagonal elements of given matrix.

C Program to Find Transpose of Matrix

Here is the C program to find transpose of a matrix. The transpose of a m x n matrix A, is another n x m matrix A^T by turning all the rows of a given matrix into columns and all the columns into rows.

The transpose of matrix A is written A^T. The ithrow, jth column element of A is the jth row, ith column element of A^T. The transpose of a matrix A can be obtained by reflecting the elements along its main diagonal. If we repeat the process of transpose on a transposed matrix A^T, it returns A with elements in their original position.

C Program to Subtract of Two Matrices

Here is the C program for subtraction of two matrix. A matrix is a two-dimentional array of elements. The size of a matrix is defined as the number of rows and columns of that matrix.

The horizontal and vertical lines of elements in a matrix are called rows and columns of a matrix. The element in the i-th row and j-th column of a matrix A is referred as (i,j), or A[i,j].
Subtracting two same-size matrices is very similar to adding matrices with the only difference being subtracting corresponding entries.

C Program to Add Two Matrices

Here is C program to add two matrices of same dimensions. A matrix is a two-dimentional array of elements. The horizontal and vertical lines of elements in a matrix are called rows and columns of a matrix.

The size of a matrix is defined as the number of rows and columns of that matrix. A matrix with M rows and N columns is called a M × N matrix. The element in the i-th row and j-th column of a matrix A is referred as (i,j), or A[i,j]. We can perform a number of operations on matrices like addition, subtraction , multiplication, inverse, row and column operations etc.