Code For Alls..!

get the code!!

Sunday, 6 August 2017

Matrix Transpose

    
                                

Given a matrix of R rows and C columns as the input, the program must print the transpose of the input matrix.

Input Format:
The first line contains R and C separated by a space.

Output Format:
C lines containing R values each, with the values separated by a space.

Boundary Conditions:
1 <= R, C <= 1000

Example Input/Output 1:
Input:
4 3
62 9 88
72 81 31
3 99 72
3 64 51

Output:
62 72 3 3
9 81 99 64
88 31 72 51

Example Input/Output 2:
Input:
3 3
1 2 3
4 5 6
7 8 9

Output:
1 4 7
2 5 8
3 6 9

c code:

#include<stdio.h>
#include <stdlib.h>
int main()
{
int r,c,i,j;
scanf("%d%d",&r,&c);
int a[r][c];
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
for(i=0;i<c;i++)
{
    for(j=0;j<r;j++)
    {
        printf("%d ",a[j][i]);
    }
    printf("\n");
}

}

No comments:

Post a Comment