Buscar

aula 12 introdução à programação

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

CCT0001 - Introdução à Programação
Aula 12: Estruturas homogêneas
Declaração
	int vetor[5][6];
Entrada
	cin >> vetor[4][1];
Saída
	cout << vetor[4][1];
Atribuição
	vetor [4][1] = 10;
Matrizes
0
1
2
3
4
5
0
1
2
3
4
10
Introdução à Programação
AULA 12: Estruturas homogêneas
Declaração
	char string[5][6];
Entrada
	cin >> vetor[4][1];
	cin >> vetor[4];
Saída
	cout << vetor[4][1];
Atribuição
	vetor [4][1] = ‘X’;
Matrizes
0
1
2
3
4
5
0
B
O
A
\n
1
N
O
I
T
E
\n
2
T
U
R
M
A
\n
3
4
X
Introdução à Programação
AULA 12: Estruturas homogêneas
Matrizes: loop aninhado
Programa que leia valores reais para uma matriz 3 x 3 e exiba todos os elementos exceto os elementos da diagonal principal.
Declarar uma matriz de inteiros 3 x 3
Loop aninhado
Loop para exibir os elementos exceto quando a linha for igual a coluna
Introdução à Programação
AULA 12: Estruturas homogêneas
Matrizes: loop aninhado
int main ()
{
 int matriz[3][3];
 int i,j;
 for(i=0;i<3;i++)
 for(j=0;j<3;j++){
 cout << "("<<i<<","<<j<<")=";
 cin >> matriz[i][j];
 }
 cout <<" FIM DA ENTRADA\n\n";
for(i=0;i<3;i++){
 for(j=0;j<3;j++)
 if (i != j)
 cout <<matriz [i][j];
	 cout << "\t";
 else
 cout << "X\t";
 cout <<"\n";
 }
system ("pause");
Introdução à Programação
AULA 12: Estruturas homogêneas
Matrizes: loop aninhado
Introdução à Programação
AULA 12: Estruturas homogêneas

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Outros materiais