Mi primer intento:
Código C:
Mi segundo intento:Ver original
#include <stdio.h> #include <stdlib.h> struct barra{ char nombre[3]; double fem; double df; }; struct nudo{ char nombre[2]; struct barra elemento; }; int main() { int i,j; struct nudo nudos[] = { {"A", {"AB", 0.0, 0.0}}, {"B", {"BA", 0.613, 0.0}}, {"B", {"BC", 0.387, -24.0}}, {"C", {"CB", 0.5, 24.0}}, {"C", {"CD", 0.5,0.0}}, {"D", {"DC", 1.0, 0.0}}, }; struct barra barras[] = {{"AB", 1.0, 2.0}, {"AC", 3.0, 4.0}}; struct nudo *dato1; struct barra *dato2; dato1 = nudos; dato2 = barras; for(j=0;i<6;j++) { *dato1++; } for(i=0;i<2;i++) { *dato2++; } return 0; }
Código C:
Mi tercer intento usando puntero a puntero:Ver original
#include <stdio.h> #include <stdlib.h> struct barra{ char nombre[3]; double fem; double df; }; struct nudo{ char nombre[2]; struct barra elemento[]; }; int main() { int i,j; struct nudo nudos[] = { {"A", {{"AB", 0.0, 0.0}}}, {"B", {{"BA", 0.613, 0.0}, {"BC", 0.387, -24.0}}}, {"C", {{"CB", 0.5, 24.0}, {"CD", 0.5,0.0}}}, {"D", {{"DC", 1.0, 0.0}}}, }; struct barra barras[] = {{"AB", 1.0, 2.0}, {"AC", 3.0, 4.0}}; struct nudo *dato1; struct barra *dato2; dato1 = nudos; dato2 = barras; for(j=0;i<6;j++) { *dato1++; } for(i=0;i<2;i++) { *dato2++; } return 0; }
Código C:
Ver original
#include <stdio.h> #include <stdlib.h> struct barra{ char nombre[3]; double fem; double df; }; struct nudo{ char nombre[2]; struct barra elemento[]; }; int main() { struct barra barra1[] = {{"AB", 1.0, 2.0}}; struct barra barra2[] = {{"BA", 0.613, 0.0}, {"BC", 0.387, -24.0}}; struct barra barra3[] = {{"CB", 0.5, 24.0}, {"CD", 0.5,0.0}}; struct barra barra4[] = {{"DC", 1.0, 0.0}}; struct barra *a, *b, *c, *d; a = barra1; b = barra2; c = barra3; d = barra4; struct nudo nudo[] = {{"A", barra1}, {"B", barra2}, {"C", barra3}, {"D", barra4}}; struct nudo *e, e = nudos return 0; }