#include <stdio.h>
void Transposta( int linhas, int colunas, int matriz[ ] [ colunas] ) {
int matrizTransposta[ colunas] [ colunas] ;
for ( int i = 0 ; i < colunas; i++ ) {
for ( int j = 0 ; j < linhas; j++ ) matrizTransposta[ i] [ j] = matriz[ j] [ i] ;
}
for ( int i = 0 ; i < linhas; i++ ) {
for ( int j
= 0 ; j
< colunas
; j
++ ) printf ( "%4d" , matrizTransposta
[ i
] [ j
] ) ; }
}
void Valores( ) {
int linhas, colunas;
printf ( "\n Digite a quantidade de linhas: \n " ) ; printf ( "Digite a quantidade de Colunas: \n " ) ; int matriz[ linhas] [ colunas] ;
printf ( "Matriz do tipo: %dx%d " , linhas
, colunas
) ; if ( linhas
== colunas
) printf ( "(Matriz quadrada)." ) ; else if ( linhas
== 1 && colunas
> 1 ) printf ( "(Matriz linha)." ) ; else if ( linhas
> 1 && colunas
== 1 ) printf ( "(Matriz coluna)." ) ; for ( int i = 0 ; i < linhas; i++ ) {
for ( int j
= 0 ; j
< colunas
; j
++ ) printf ( "a%d%d " , i
+ 1 , j
+ 1 ) ; }
printf ( "Digite os valores de: \n " ) ; for ( int i = 0 ; i < linhas; i++ ) {
for ( int j = 0 ; j < colunas; j++ ) {
printf ( "a%d%d " , i
+ 1 , j
+ 1 ) ; scanf ( "%d" , & matriz
[ i
] [ j
] ) ; }
}
for ( int i = 0 ; i < linhas; i++ ) {
for ( int j
= 0 ; j
< colunas
; j
++ ) printf ( "%4d" , matriz
[ i
] [ j
] ) ; }
Transposta( linhas, colunas, matriz) ;
}
int main( ) {
int end;
printf ( "\n ***CALCULOS DE MATRIZES*** \n " ) ; do {
printf ( "\n Matriz Transposta\n " ) ; Valores( ) ;
printf ( "\n Digite 1 para sair ou digite qualquer outro numero para Continuar:\n " ) ; } while ( end != 1 ) ;
}
//https://pt.stackoverflow.com/q/244422/101
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIFRyYW5zcG9zdGEoaW50IGxpbmhhcywgaW50IGNvbHVuYXMsIGludCBtYXRyaXpbXVtjb2x1bmFzXSkgewoJaW50IG1hdHJpelRyYW5zcG9zdGFbY29sdW5hc11bY29sdW5hc107CiAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBjb2x1bmFzOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGxpbmhhczsgaisrKSBtYXRyaXpUcmFuc3Bvc3RhW2ldW2pdID0gbWF0cml6W2pdW2ldOwogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KICAgZm9yIChpbnQgaSA9IDA7IGkgPCBsaW5oYXM7IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgY29sdW5hczsgaisrKSBwcmludGYoIiU0ZCIsIG1hdHJpelRyYW5zcG9zdGFbaV1bal0pOwogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KfQoKdm9pZCBWYWxvcmVzKCkgewogICAgaW50IGxpbmhhcywgY29sdW5hczsKICAgIHByaW50ZigiXG5EaWdpdGUgYSBxdWFudGlkYWRlIGRlIGxpbmhhczogXG4iKTsKICAgIHNjYW5mKCIlZCIsICZsaW5oYXMpOwogICAgcHJpbnRmKCJEaWdpdGUgYSBxdWFudGlkYWRlIGRlIENvbHVuYXM6IFxuIik7CiAgICBzY2FuZigiJWQiLCAmY29sdW5hcyk7CiAgICBpbnQgbWF0cml6W2xpbmhhc11bY29sdW5hc107CiAgICBwcmludGYoIk1hdHJpeiBkbyB0aXBvOiAlZHglZCAiLCBsaW5oYXMsIGNvbHVuYXMpOwogICAgaWYgKGxpbmhhcyA9PSBjb2x1bmFzKSBwcmludGYoIihNYXRyaXogcXVhZHJhZGEpLiIpOwogICAgZWxzZSBpZiAobGluaGFzID09IDEgJiYgY29sdW5hcyA+IDEpIHByaW50ZigiKE1hdHJpeiBsaW5oYSkuIik7CiAgICBlbHNlIGlmKGxpbmhhcyA+IDEgJiYgY29sdW5hcyA9PSAxKSBwcmludGYoIihNYXRyaXogY29sdW5hKS4iKTsKICAgIHByaW50ZigiXG4iKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGluaGFzOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGNvbHVuYXM7IGorKykgcHJpbnRmKCJhJWQlZCAiLCBpICsgMSwgaiArIDEpOwogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KICAgIHByaW50ZigiRGlnaXRlIG9zIHZhbG9yZXMgZGU6IFxuIik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxpbmhhczsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBjb2x1bmFzOyBqKyspIHsKICAgICAgICAgICAgcHJpbnRmKCJhJWQlZCAiLCBpICsgMSwgaiArIDEpOwogICAgICAgICAgICBzY2FuZigiJWQiLCAmbWF0cml6W2ldW2pdKTsKICAgICAgICB9CiAgICB9CiAgICBwcmludGYoIlxuIik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxpbmhhczsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBjb2x1bmFzOyBqKyspIHByaW50ZigiJTRkIiwgbWF0cml6W2ldW2pdKTsKICAgICAgICBwcmludGYoIlxuIik7CiAgICB9CiAgICBwcmludGYoIlxuIik7CiAgICBUcmFuc3Bvc3RhKGxpbmhhcywgY29sdW5hcywgbWF0cml6KTsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgZW5kOwogICAgcHJpbnRmKCJcbioqKkNBTENVTE9TIERFIE1BVFJJWkVTKioqIFxuIik7CiAgICBkbyB7CiAgICAgICAgcHJpbnRmKCJcbk1hdHJpeiBUcmFuc3Bvc3RhXG4iKTsKICAgICAgICBWYWxvcmVzKCk7CiAgICAgICAgcHJpbnRmKCJcbkRpZ2l0ZSAxIHBhcmEgc2FpciBvdSBkaWdpdGUgcXVhbHF1ZXIgb3V0cm8gbnVtZXJvIHBhcmEgQ29udGludWFyOlxuIik7CiAgICAgICAgc2NhbmYoIiVkIiwgJmVuZCk7CiAgICB9IHdoaWxlIChlbmQgIT0gMSk7Cn0KCi8vaHR0cHM6Ly9wdC5zdGFja292ZXJmbG93LmNvbS9xLzI0NDQyMi8xMDE=