Program to find Inverse of Matrix C++

Today we are going to write a program to find the inverse of matrix C++, so let’s start with the what is the inverse of a matrix.

Inverse of a Matrix:

For a square matrix A, the inverse is written A-1. When A is multiplied by A-1 the result is the identity matrix I. Non-square matrices do not have inverses.

Note: Not all square matrices have inverses. A square matrix which has an inverse is called invertible or nonsingular, and a square matrix without an inverse is called non-invertible or singular.


AA-1 = A-1A = I

Example:For matrix , its inverse is since
AA-1 = and A-1A = .


Program to find Inverse of a Matrix C++:


C++ Program to generate CAPTCHA and verify user

What is CAPTCHA?

A CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a test to determine whether the user is human or not.

c++ program to generate captcha


So, the task is to generate unique CAPTCHA every time and to tell whether the user is human or not by asking user to enter the same CAPTCHA as generated automatically and checking the user input with the generated CAPTCHA.

So before writing a c++ program to generate CAPTCHA we must understand with the help of example.


The set of characters to generate CAPTCHA are stored in a character array chrs[] which contains (a-z, A-Z, 0-9), therefore size of chrs[] is 62.

To generate a unique CAPTCHA every time, a random number is generated using rand() function (rand()%62) which generates a random number between 0 to 61 and the generated random number is taken as index to the character array chrs[] thus generates a new character of captcha[] and this loop runs n (length of CAPTCHA) times to generate CAPTCHA of given length. Let’s write a C++ program to generate CAPTCHA

C++ program to generate CAPTCHA and verify user:



Hope you like it easy, please comment if you face any problem.

Method overloading vs Method Overriding

Difference between Method Overloading vs Method overriding:

  • Overloading can occur without inheritance. Overriding of functions occurs when one class is inherited from another class.


  • Overloaded functions must differ in function signature i.e. either number of parameters or type of parameters should differ. In overriding, function signatures must be same.


  • Overloaded functions are in same scope; whereas Overridden functions are in different scopes.


Method OverloadingMethod Overriding
DefinitionIn Method Overloading, Methods of the same class shares the same name but each method must have different number of parameters or parameters having different types and order.In Method Overriding, sub class have the same method with same name and exactly the same number and type of parameters and same return type as a super class.
MeaningMethod Overloading means more than one method shares the same name in the class but having different signature.Method Overriding means method of base class is re-defined in the derived class having same signature.
BehaviorMethod Overloading is to “add” or “extend” more to method’s behavior.Method Overriding is to “Change” existing behavior of method.
PolymorphismIt is a compile time polymorphism.It is a run time polymorphism.
InheritanceIt may or may not need inheritance in Method Overloading.It always requires inheritance in Method Overriding.
SignatureIn Method Overloading, methods must have different signature.In Method Overriding, methods must have same signature.
Relationship of MethodsIn Method Overloading, relationship is there between methods of same class.In Method Overriding, relationship is there between methods of super class and sub class.
CriteriaIn Method Overloading, methods have same name different signatures but in the same class.In Method Overriding, methods have same name and same signature but in the different class.
No. of ClassesMethod Overloading does not require more than one class for overloading.Method Overriding requires at least two classes for overriding.


Diagram to understand exact difference :-


method overloading vs method overriding



Example in program:-

Method Overloading:

Method Overriding:



Red Black-Tree(RB-Tree) implementation in C++

Red Black-Tree (RB-Tree):

A red-black tree is a binary search tree with one extra attribute for each node: the colour, which is either red or black. It has following properties:

  1. Every node is either red or black.
  2. Every leaf (NULL) is black.
  3. If a node is red, then both its children are black.
  4. Every simple path from a node to a descendant leaf contains the same number of black nodes.



C++ program to implement RB-Tree:


Sample Output

Implement function overloading to find Area of Shapes

What is Function Overloading?

When we define one function with more than one definition it is known as Function overloading. For example:

We can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. We can not overload function declarations that differ only by return type.

Program to implement Function Overloading to find area of different shapes:

Sample Output:

Solution for Tower of Hanoi C++

What is Tower of Hanoi?

All must be well aware of the problem of Tower of Hanoi, for those who don’t know, let’s discuss it once again.

The Tower of Hanoi (also called the Tower of Brahma or Lucas’ Tower, and sometimes pluralized) is a mathematical game or puzzle.


tower of hanoi


It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

  • Only one disk can be moved at a time.
  • Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
  • No disk may be placed on top of a smaller disk.

Animated Solution:


tower of hanoi solution


 We can solve it in 2 ways:

  1. Using Recursion
  2. Using Stacks

Using Recursion:

Sample Output:


Program to solve Tower of Hanoi C++ using Stack

Sample Output: