C++ Program to Find if an Array is an Identity Matrix2 min read

In this tutorial, we will learn and write a C++ program to check whether a given matrix is an identity matrix or not. To understand the coding, you should have knowledge of the following topics in C++ programming:


Identity Matrix:

A square matrix is said to be an identity matrix if each entry on its diagonal is equal to 1 and the rest are 0. Example:

Matrix of dimension 3 by 3:
1 0 0
0 1 0
0 0 1


Explanation: The program takes user input for the number of rows and columns of a matrix. The values are of each element are also taken from the user.

Before entering the elements of the matrix, the program also checks for the matrix to be a square matrix. If it is a square matrix then the execution control moves to the next line but if not then the program is exited.

The program checks the diagonals matrix for 1 and the rest for 0. If the conditions are found to be true then the entered matrix is identity matrix else not.

Now let us go through a program for Identity Matrix in C++.


C++ Program to Find if an Array is an Identity Matrix

Output:

identity matrix in C++

MORE

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …