Advertisement Remove all ads

Write a C Program to (10 M) I. Create a 2d Array [Matrix] [In Main Function] Ii. Write a Function to Read 2d Array[Matrix] Iii. Write a Function that Will Return True - Structured Programming Approach

Short Note

Write a C program to
i. Create a 2D array [Matrix] [in main function]
ii. Write a function to read 2D array[Matrix]
iii. Write a function that will return true(1) if entered matrix is symmetric or false(0) is not symmetric.
iv. Print whether entered matrix is symmetric or not [in main function]

Advertisement Remove all ads

Solution

Program:
#include<stdio.h>
void main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
clrscr();
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of the matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &matrix[c][d]);
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
transpose[d][c] = matrix[c][d];
if (m == n)
{
for (c = 0; c < m; c++)
{
for (d = 0; d < m; d++)
{
if (matrix[c][d] != transpose[c][d])
break;
}
if (d != m)
break;
}
if (c == m)
printf("The matrix is symmetric.\n");
else
printf("The matrix isn't symmetric.\n");
}
else
printf("The matrix isn't symmetric.\n");
getch();
}
Output:
Enter the number of rows and columns of matrix
2 2
Enter elements of matrix
1 2 3 4
The matrix isn’t symmetric.
Concept: Array
  Is there an error in this question or solution?
Advertisement Remove all ads

APPEARS IN

Advertisement Remove all ads
Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×