Copia valor de uma matriz para dentro de um vetor. Utilizando variáveis globais.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
// Copiar Valores da Matriz para um vetor.
int mat[2][2][2],vet[8],p,l,c,i; // profundidade, linha, coluna
void encheMatriz() {
cout << "Digite os valores da matriz(2,2,2)\n";
for (p=0;p<2;p++)
{
for (l=0;l<2;l++)
{
for (c=0;c<2;c++)
{
cin >> mat[p][l][c];
}
}
}
}
void passaVet()
{
for (p=0;p<2;p++)
{
for (l=0;l<2;l++)
{
for (c=0;c<2;c++)
{
vet[i] = mat[p][l][c];
i = i +1;
}
}
}
}
void mostraVet()
{
for (i=0;i<8;i++)
cout << vet[i] << " ";
}
int main() {
encheMatriz();
passaVet();
mostraVet();
getch();
}
0 comentários: (+add yours?)
Postar um comentário