0% found this document useful (0 votes)
145 views1 page

WAP To Check If A Given Matrix Is Symmetric or Not

This C program defines a 2D array to represent a matrix. It prompts the user to enter the number of rows/columns, then enters values for the matrix. The program displays the original matrix, then checks if the matrix is symmetric by comparing each element to its transpose - if all pairs match, it is symmetric, otherwise it is not symmetric.

Uploaded by

Sayan Chowdhury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views1 page

WAP To Check If A Given Matrix Is Symmetric or Not

This C program defines a 2D array to represent a matrix. It prompts the user to enter the number of rows/columns, then enters values for the matrix. The program displays the original matrix, then checks if the matrix is symmetric by comparing each element to its transpose - if all pairs match, it is symmetric, otherwise it is not symmetric.

Uploaded by

Sayan Chowdhury
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int main()
{
int a[10][10], rc, i, j, flag = 0;
printf("Enter number of rows or columns of the square matrix: ");
scanf("%d", &rc);

// Storing elements of the matrix


printf("\nEnter elements of matrix:\n");
for(i=0; i<=rc-1; i++)
for(j=0; j<=rc-1; j++)
{
printf("Enter element a%d%d: ",i+1, j+1);
scanf("%d", &a[i][j]);
}

// Displaying the matrix a[][] */


printf("\nEntered Matrix: \n");
for(i=0; i<=rc-1; i++)
for(j=0; j<=rc-1; j++)
{
printf("%d ", a[i][j]);
if (j == rc-1)
printf("\n\n");
}

// checking with the transpose of matrix a


for(i=0; i<=rc-1; i++)
for(j=0; j<=rc-1; j++)
{
if(a[j][i] != a[i][j])
flag = 1;
}
if (flag == 0)
printf ("The matrix is Symmetric.\n");
else
printf("The matrix is Not Symmetric.\n");
}

You might also like