ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

C program to check two matrices are identical or not

Here, we are going to learn how to check whether two matrices are identical or not in C programming language?
Submitted by Nidhi, on July 13, 2021

Problem Solution:

Given two matrices, we have to check whether they are identical or not using C program.

Program:

The source code to check two matrices are identical or not is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to check two matrices are identical or not

#include <stdio.h>
#define SIZE 3

int areIdentical(int Matrix1[][SIZE], int Matrix2[][SIZE])
{
    int i = 0;
    int j = 0;

    for (i = 0; i < SIZE; i++) {
        for (j = 0; j < SIZE; j++) {
            if (Matrix1[i][j] != Matrix1[i][j])
                return 0;
        }
    }
    return 1;
}

int main()
{
    int Matrix1[SIZE][SIZE] = {
        { 1, 2, 3 },
        { 2, 1, 3 },
        { 3, 2, 1 },
    };

    int Matrix2[SIZE][SIZE] = {
        { 1, 2, 3 },
        { 2, 1, 3 },
        { 3, 2, 1 },
    };

    if (areIdentical(Matrix1, Matrix2))
        printf("Both matrices are identical\n");
    else
        printf("Matrices are not identical\n");

    return 0;
}

Output:

Both matrices are identical

Explanation:

In the above program, we created two functions areIdentical() and main() function. The areIdentical() function is a user-defined function, it is used to check that, given matrices are identical or not.

In the main() function, we created two matrices Matrix1, Matrix2. Then we compared both matrices using areIdentical() function and then we printed the appropriate message on the console screen.

C Two-dimensional Arrays Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.