Write C Program to Find the Transpose of a given Matrix


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


  1. #include <stdio.h>
  2.  
  3. void main()
  4. {
  5. static int array[10][10];
  6. int i, j, m, n;
  7.  
  8. printf("Enter the order of the matrix \n");
  9. // Inputing elements in matrix from user
  10. scanf("%d %d", &m, &n);
  11. printf("Enter the coefiicients of the matrix\n");
  12. for (i = 0; i < m; ++i)
  13. {
  14. for (j = 0; j < n; ++j)
  15. {
  16. scanf("%d", &array[i][j]);
  17. }
  18. }
  19. //Printing the original matrix
  20. printf("The given matrix is \n");
  21. for (i = 0; i < m; ++i)
  22. {
  23. for (j = 0; j < n; ++j)
  24. {
  25. printf(" %d", array[i][j]);
  26. }
  27. printf("\n");
  28. }
  29. //Printing the transpose of matrix
  30. printf("Transpose of matrix is \n");
  31. for (j = 0; j < n; ++j)
  32. {
  33. for (i = 0; i < m; ++i)
  34. {
  35. printf(" %d", array[i][j]);
  36. }
  37. printf("\n");
  38. }
  39. }
  40.  

Result

C language techstudy.org

     






Related Topics




Popular Posts