Last active
March 30, 2016 19:12
-
-
Save JuniorPolegato/f26ff7511958287c5fa84291c7082c77 to your computer and use it in GitHub Desktop.
Recombina vetores elemento por elemento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char *argv[]){ | |
int i; | |
// Vetor de subvetores de inteiros com tamanhos não definidos | |
int* A[] = {(int[]){4, 5}, (int[]){1}, (int[]){3, 6, 7}}; | |
// Vetor com o tamanho de cada subvetor | |
int An[] = {2, 1, 3}; | |
// Tamanho do vetor | |
int N = sizeof(A) / sizeof(int*); | |
printf("N: %i\n", N); | |
// Vetor com os índices de cada subvetor iniciando com zeros | |
int *in = (int*)malloc(sizeof(int) * N); | |
bzero(in, sizeof(int) * N); | |
// Executa o bloco enquanto o primeiro índice for válido | |
while (in[0] < An[0]){ | |
// Imprime cada valor encontrado no seu respectivo índice | |
printf("{"); | |
for (i = 0; i < N; i++) | |
printf("%i, ", A[i][in[i]]); | |
printf("\b\b}\n"); | |
// Aumenta o índice do último ao primeiro conforme seu limite | |
for (i = N - 1; i > -1; i--) { | |
in[i]++; | |
if (in[i] < An[i] || i == 0) | |
break; | |
else | |
in[i] = 0; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment