Documente Academic
Documente Profesional
Documente Cultură
Vetor Multidimensional
1
Vetor Multidimensional
O nome do array é c
Coluna 0 Coluna 1 Coluna 2 Coluna 3
Linha 0 C [0] [0] C [0] [1] C [0] [2] C [0] [3]
Linha 1 C [1] [0] C [1] [1] C [1] [2] C [1] [3]
Linha 2 C [2] [0] C [2] [1] C [2] [2] C [2] [3]
Índice da Coluna
Índice da Linha
Nome de um elemento
do array individual
2
Declaração e inicialização de Matriz
Declaração
int multiVec[100][200][50];
3
Acesso ao Elemento
Manipulação
4
Exemplo
int main(){
int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } },
array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 },
array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } };
for ( int i = 0; i < 2; i++ )
for ( int j = 0; j < 3; j++ )
cout <<i<<j<<"-"<<array1[ i ][ j ] << ' ';
cout << "\n";
for ( int i = 0; i < 2; i++ )
for ( int j = 0; j < 3; j++ )
cout <<i<<j<<"-"<<array2[ i ][ j ] << ' ';
cout << "\n";
for ( int i = 0; i < 2; i++ )
for ( int j = 0; j < 3; j++ )
cout <<i<<j<<"-"<<array3[ i ][ j ] << ' ';
}
ENGENHARIAS – LINGUAGEM DE PROGRAMAÇÃO – Henry Lubanco 113
Exemplo
#include<iostream>
#define LINHA 2
#define COLUNA 3
using namespace std;
int main ( )
{
int vec [LINHA][COLUNA]={23 ,45 ,32 ,78 ,98, 99} , i , j, s=0;
for ( i =0; i<LINHA; i++)
for ( j =0; j<COLUNA; j++)
s=s + vec [ i ][ j ] ;
cout<<" Soma : "<<s<<endl ;
}
ENGENHARIAS – LINGUAGEM DE PROGRAMAÇÃO – Henry Lubanco 114
5
Exercícios
Exercícios
6
Exercícios
Exercícios