0% found this document useful (0 votes)
208 views

Write A Program To Take A 4 4 Matrix As Input and Print The Diagonals

The document provides C code examples for several matrix operations: 1) Printing the diagonals of a 4x4 matrix. 2) Checking if two matrices are equal by comparing all elements. 3) Checking if a matrix is symmetric by comparing diagonal elements. 4) Finding the largest and smallest numbers in a 5x5 matrix. It also lists operations for swapping diagonal elements in the same row and calculating the sum of elements in the "gray region" of a matrix.

Uploaded by

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

Write A Program To Take A 4 4 Matrix As Input and Print The Diagonals

The document provides C code examples for several matrix operations: 1) Printing the diagonals of a 4x4 matrix. 2) Checking if two matrices are equal by comparing all elements. 3) Checking if a matrix is symmetric by comparing diagonal elements. 4) Finding the largest and smallest numbers in a 5x5 matrix. It also lists operations for swapping diagonal elements in the same row and calculating the sum of elements in the "gray region" of a matrix.

Uploaded by

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

 Write a program to take a 4*4 matrix as input and print the diagonals.

 Write a program to check whether two matrices are equal or not.

1.
2. #include <stdio.h>
3.
4. #define SIZE 3
5.
6. int main()
7. {
8. int A[SIZE][SIZE];
9. int B[SIZE][SIZE];
10.
11. int row, col, isEqual;
12.
13. printf("Enter elements in matrix A of size %dx%d: \n", SIZE, SIZE);
14. for(row=0; row<SIZE; row++)
15. {
16. for(col=0; col<SIZE; col++)
17. {
18. scanf("%d", &A[row][col]);
19. }
20. }
21.
22. printf("\nEnter elements in matrix B of size %dx%d: \n");
23. for(row=0; row<SIZE; row++)
24. {
25. for(col=0; col<SIZE; col++)
26. {
27. scanf("%d", &B[row][col]);
28. }
29. }
30.
31. isEqual = 1;
32.
33. for(row=0; row<SIZE; row++)
34. {
35. for(col=0; col<SIZE; col++)
36. {
37.
38. if(A[row][col] != B[row][col])
39. {
40. isEqual = 0;
41. break;
42. }
43. }
44. }
45.
46.
47. if(isEqual == 1)
48. {
49. printf("\nMatrix A is equal to Matrix B");
50. }
51. else
52. {
53. printf("\nMatrix A is not equal to Matrix B");
54. }
55.
56. return 0;
57. }

 Write a program to check whether a matrix is a symmetric matrix or not. Symmetric matrix is
the matrix whose elements are diagonally mirrored to each other .

1. #include<stdio.h>
2. void main()
3. {
4. int a[10][10],i,j,m;
5. clrscr();
6. printf("Enter order of square matrix: ");
7. scanf("%d",&m);
8. for(i=1;i<=m;i++)
9. {
10. for(j=1;j<=m;j++)
11. {
12. printf("Enter value of a[%d][%d]: ",i,j);
13. scanf("%d",&a[i][j]);
14. }
15. }
16. for(i=1;i<=m;i++)
17. {
18. for(j=1;j<=m;j++)
19. {
20. if(a[i][j]!=a[j][i])
21. {
22. printf("\n\nMatrix is not symmetric");
23. getch();
24. exit(0);
25. }
26. }
27. }
28. printf("\n\nMatrix is symmetric");
29. getch();
30. }
31.
32.
33. isEqual = 1;
34.
35. for(row=0; row<SIZE; row++)
36. {
37. for(col=0; col<SIZE; col++)
38. {
39.
40. if(A[row][col] != B[row][col])
41. {
42. isEqual = 0;
43. break;
44. }
45. }
46. }
47.
48.
49. if(isEqual == 1)
50. {
51. printf("\nMatrix A is equal to Matrix B");
52. }
53. else
54. {
55. printf("\nMatrix A is not equal to Matrix B");
56. }
57.
58. return 0;
59. }
 Write a program to find the largest and smallest number from a 5*5 matrix.

1. #include<stdio.h>
2. main()
3. {
4. int lnum[5][5];
5. int i,j;
6. for(i=0;i<=4;i++)
7. {
8. printf("\n");
9. for(j=0;j<=4;j++)
10. {
11. printf("Enter the number");
12. scanf("%d",&lnum[i][j]);
13. }
14. }
15. for(i=0;i<=4;i++)
16. {
17. printf("\n");
18. for(j=0;j<=4;j++)
19. {
20. printf("%d",lnum[i][j]);
21. }
22. }
23. getch();
24. }

 Write a program which can swap the diagonal elements in same row of a matrix .
 Write a program which can calculate the sum of elements of gray region .

You might also like