Converter um vetor em uma matriz multidimensional
Publicado por JIMJR (última atualização em 07/06/2011)
[ Hits: 11.957 ]
Este script pega um vetor e o transforma em uma matriz multidimensional de tamanho de dimensões iguais, em breve vou fazer outro com o tamanho variado.
Foi feito no dev/c++ for Windows, portanto, se quiser compilar no Linux terá que retirar a lib conio.h e substituí-la por ncurses.h ou simplesmente trocar o comando getch() por outro similar.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#define NUM 2
int main() {
int mat_tri[NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM][NUM];
int indx;
int vet_mil[NUM^16];
for(indx = 0; indx < pow(NUM,16); indx++) {
vet_mil[indx] = indx + 1;
printf("( %i , %i , %i , %i , %i , %i , %i , %i , %i , %i , %i , %i , %i , %i , %i , %i ) = %i \n",
(int)floor(indx/pow(NUM,15)),
(int)floor(indx/pow(NUM,14)) % NUM,
(int)floor(indx/pow(NUM,13)) % NUM,
(int)floor(indx/pow(NUM,12)) % NUM,
(int)floor(indx/pow(NUM,11)) % NUM,
(int)floor(indx/pow(NUM,10)) % NUM,
(int)floor(indx/pow(NUM,9)) % NUM,
(int)floor(indx/pow(NUM,8)) % NUM,
(int)floor(indx/pow(NUM,7)) % NUM,
(int)floor(indx/pow(NUM,6)) % NUM,
(int)floor(indx/pow(NUM,5)) % NUM,
(int)floor(indx/pow(NUM,4)) % NUM,
(int)floor(indx/pow(NUM,3)) % NUM,
(int)floor(indx/pow(NUM,2)) % NUM,
(int)floor(indx/pow(NUM,1)) % NUM,
indx % NUM,
vet_mil[indx]);
mat_tri[(int)floor(indx/pow(NUM,15)) ]
[(int)floor(indx/pow(NUM,14)) % NUM]
[(int)floor(indx/pow(NUM,13)) % NUM]
[(int)floor(indx/pow(NUM,12)) % NUM]
[(int)floor(indx/pow(NUM,11)) % NUM]
[(int)floor(indx/pow(NUM,10)) % NUM]
[(int)floor(indx/pow(NUM,9)) % NUM]
[(int)floor(indx/pow(NUM,8)) % NUM]
[(int)floor(indx/pow(NUM,7)) % NUM]
[(int)floor(indx/pow(NUM,6)) % NUM]
[(int)floor(indx/pow(NUM,5)) % NUM]
[(int)floor(indx/pow(NUM,4)) % NUM]
[(int)floor(indx/pow(NUM,3)) % NUM]
[(int)floor(indx/pow(NUM,2)) % NUM]
[(int)floor(indx/pow(NUM,1)) % NUM]
[indx % NUM] = vet_mil[indx];
}
getch();
return 0;
}
Parte 3 - Sessão de estudo sobre VETORES
Nenhum comentário foi encontrado.
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Como fazer a conversão binária e aplicar as restrições no Linux
Como quebrar a senha de um servidor Linux Debian
Como bloquear pendrive em uma rede Linux
Um autoinstall.yaml para Ubuntu com foco em quem vai fazer máquina virtual
Instalar GRUB sem archinstall no Arch Linux em UEFI Problemático
Fiz uma pergunta no fórum mas não consigo localizar [RESOLVIDO] (21)









