Richard AR
Richard AR

Reputation: 59

program cannot find transpose of a matrix

i created this c program that finds the transpose of a matrix but unfortunately it is not working. i am new to c program and this is not working

please someone help

this is a assignment and i tried to complete it myself and i really don't know why this is not working

i would really appreciate anyone who could help me


int main()
{


int matrix[3][3], i, j, n;

for (i=0;i<3;i++){
    
    for(j=0;j<3;j++){
        
        printf("enter the number for position x[%d][%d]",i , j);
        
        scanf("%d", &n);
        
        matrix[i][j] = n;
        
    }
    
}



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


    }
    
    printf("\n");
}


printf("\n\n\n\n");
int matrix2[3][3]={};


  
  for (i=0;i<3;i++){
    
    for(j=0;j<3;j++){
        
      matrix[i][j]=matrix2[j][i];

    }
    
}
  
  
  
  
for (i=0;i<3;i++){
    
    for(j=0;j<3;j++){
        
    printf("%d", matrix2[i][j]);


    }
    
    printf("\n");
}




    return 0;
}

Upvotes: 0

Views: 42

Answers (1)

Mihir_09_
Mihir_09_

Reputation: 36

The following line is written wrong:

matrix[i][j]=matrix2[j][i]; 

Assignment of matrix to matrix2 should be done this way:

matrix2[i][j]=matrix[j][i];

Upvotes: 2

Related Questions