C program to transpose a matrix


SUBMITTED BY: Guest

DATE: Jan. 22, 2014, 12:11 a.m.

FORMAT: Text only

SIZE: 832 Bytes

HITS: 1016

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int m, n, c, d, matrix[10][10], transpose[10][10];
  5. printf("Enter the number of rows and columns of matrix ");
  6. scanf("%d%d",&m,&n);
  7. printf("Enter the elements of matrix \n");
  8. for( c = 0 ; c < m ; c++ )
  9. {
  10. for( d = 0 ; d < n ; d++ )
  11. {
  12. scanf("%d",&matrix[c][d]);
  13. }
  14. }
  15. for( c = 0 ; c < m ; c++ )
  16. {
  17. for( d = 0 ; d < n ; d++ )
  18. {
  19. transpose[d][c] = matrix[c][d];
  20. }
  21. }
  22. printf("Transpose of entered matrix :-\n");
  23. for( c = 0 ; c < n ; c++ )
  24. {
  25. for( d = 0 ; d < m ; d++ )
  26. {
  27. printf("%d\t",transpose[c][d]);
  28. }
  29. printf("\n");
  30. }
  31. return 0;
  32. }

comments powered by Disqus