-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatriz_transposta.cpp
More file actions
48 lines (43 loc) · 1.23 KB
/
matriz_transposta.cpp
File metadata and controls
48 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
/*
Elabore um algoritmo que leia uma matriz 3x3 e gere automaticamente uma nova matriz que seja a matriz transposta da primeira (troque as linhas por colunas).
*/
int main()
{
int matriz[3][3];
int matrizTransposta[3][3];
int l, c; // l = linha, c = coluna :)
for (l = 0; l < 3; l++)
{
for (c = 0; c < 3; c++) // lendo toda a matriz original
{
cout << "Escreva a linha: " << l << " na coluna: " << c << endl;
cin >> matriz[l][c];
}
}
for (l = 0; l < 3; l++)
{
for (c = 0; c < 3; c++)
{
matrizTransposta[l][c] = matriz[c][l]; // Formando a matriz composta
}
}
cout << "Matriz original: " << endl;
for (l = 0; l < 3; l++) // exibindo a matriz original
{
for (c = 0; c < 3; c++)
{
cout << "[" << l << "]" << "[" << c << "]" << " = " << matriz[l][c] << endl;
}
}
cout << "Matriz Transposta: " << endl;
for (l = 0; l < 3; l++) // exibindo a matriz composta
{
for (c = 0; c < 3; c++)
{
cout << "[" << l << "]" << "[" << c << "]" << " = " << matrizTransposta[l][c] << endl;
}
}
return 0;
}