Code Scrappers


Matrix Transpose - C Program


                    #include<stdio.h>
                    #include<stdlib.h>

                    void main()
                    {
                        int a[8][8], i, j, m, n;

                        printf("Enter the no. of rows of the matrix \n");

                        scanf("%d", &m);

                        printf("Enter the no. of columns of the matrix \n");

                        scanf("%d", &n);

                        printf("Enter elements of matrix \n");

                        for(i=0; i<m; i++)
                        {
                            for(j=0; j<n; j++)
                            {
                                scanf("%d", &a[i][j]);

                            }

                        }

                        printf("transpose of matrix : \n");

                        for(i=0; i<n; i++)
                        {
                            for(j=0; j<m; j++)
                            {
                                printf("%d\t", a[j][i]);

                            }

                            printf("\n");

                        }

                    }


                



Output

            Enter the size of the matrix
            2
            2
            Enter elements in matrix of size 2x2:
            1
            2
            3
            4
            Transpose of matrix:
            1       3
            2       4