C Program to Interchange Diagonals of a Matrix

In this tutorial you will learn about the C Program to Interchange Diagonals of a Matrix and its application with practical example.

C Program to Interchange Diagonals of a Matrix

In this tutorial, we will learn to create a C program that will Interchange Diagonals of a Matrix using C programming.

Prerequisites

Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.

Algorithm:-

Below is an example of the matrix before interchanging of diagonals figure1

Figure1

Then After interchanging of diagonals of the matrix is given below.

Figure 2

With the help of this program, we can Interchange the Diagonals of a Matrix.

Program to Interchange Diagonals of a Matrix:-

In this tutorial, we will interchange Diagonal Elements in a Matrix. First, we will take the size of the matrix from the user, and then we will take the input elements of the matrix. Now we will swap the diagonal elements in the matrix. At last, we will print the result matrix to the user.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

  • a[10][10]= it will hold the integer value.
  • x = it will hold the integer value for the loop.
  • y = it will hold the integer value for the loop.
  • i= it will hold the input integer value for rows.
  • j= it will hold the input integer value for columns.

Taking the size and the elements of the matrix from the user.

Interchanging the elements of the diagonals of the matrix.

Printing the matrix after interchanging the elements of the Matrix.

In this tutorial we have learn about the C Program to Interchange Diagonals of a Matrix and its application with practical example. I hope you will like this tutorial.