Matrix Addition in C using Linked List

The program below is the code for Matrix Addition in C using Linked List.

Basically here the matrix elements (Aij) are represented by linked list nodes.

Each element (node) has:

  • row  –  Stores the row value of the element.
  • col    –  Stores the column value of the element.
  • data  – Store the value of the element.
  • *next -Store the address of next element (node).

In this program we are using two matrix. Each matrix has:

  • rows        – Stores the count of the total number of rows in the matrix.
  • columns – Stores the count of the total number of columns in the matrix.
  • *head      – Sores the head element.
  • *tail         – Stores the tail element.

Code

Output

Case 1: When the order of the two matrix are the same.

matrix addition in x using linked list

Case 2: When the order of the two matrix are not same.

matrix addition in c

Case 3: When one of the matrix is empty.

matrix addition code

The program displays the menu in loop which can handle multiple operation like

  • Displaying matrix.
  • Inputting elements into the matrix.
  • Adding two matrix.
  • Exit & more.

Hence more cases are possible instead of three cases stated here. So try the program by yourself.

Also read:

Merge Sort in C.

How to run c Program in command prompt using gcc.

admin

I am a B.tech IT Student from India. Technology and programming is the most enthusiastic thing for me in this world. I like learning new techniques and use them for real-world application because I feel tech is future. Let's learn and grow TOGETHER.