-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelaciones.c
106 lines (94 loc) · 2.52 KB
/
relaciones.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
struct matriz{
int conjuntoDePartida[4];
char conjuntoDeLlegada[4];
};
struct relaciones{
int dominio[16];
char imagen[16];
};
int verificarInt(int elemento,int primerConjunto[]){
int j=1;
for(int i=0; i < sizeof(primerConjunto); i++){
if(primerConjunto[i] == elemento){
j=0;
break;
}
}
if(!j){
printf("No era un valor del primer conjunto\n");
}
return j;
}
int verificarChar(char elemento,char segundoConjunto[]){
int j=1;
for(int i=0;i<sizeof(segundoConjunto);i++){
if(segundoConjunto[i]==elemento){
j= 0;
break;
}
}
if(!j){
printf("No era un valor del segundo conjunto\n");
}
return j;
}
void pedirElemento1(int *unElemento){
printf("Ingrese un valor del primer conjunto:\n");
fflush(stdin);
scanf("%d",unElemento);
}
void pedirElemento2(char *unElemento){
printf("Ingrese el valor del segundo conjuto:\n");
fflush(stdin);
scanf("%c",unElemento);
}
void establecerRelaciones(int *conjuntoPartida, char *conjuntoLlegada){
printf("\nPara establecer relaciones, ingrese un valor de cada conjunto\n");
printf("cuando haya establecido la última, presione +");
int elementoDePrimerConjunto = 0;
char elementoDeSegundoConjunto;
struct matriz mat;
struct relaciones rel;
int indice = 0;
int condicion = 1;
while(condicion){
do{
pedirElemento1(&elementoDePrimerConjunto);
rel.dominio[indice] = elementoDePrimerConjunto;
} while(verificarInt(elementoDePrimerConjunto,conjuntoPartida));
do{
pedirElemento2(&elementoDeSegundoConjunto);
rel.imagen[indice] = elementoDeSegundoConjunto;
} while(verificarChar(elementoDeSegundoConjunto,conjuntoLlegada));
indice++;
condicion = 0;
printf("ingresar otra relación? 1=> Si, 0=> No");
fflush(stdin);
scanf("%d",&condicion);
}
}
void mostrarConjuntos(int conjuntoPartida[],char conjuntoLlegada[]){
int sizeArray;
sizeArray=sizeof(conjuntoPartida);
printf("El conjunto 1 es:\n");
for(int i=0;i<sizeArray;i++){
printf("%d, ",conjuntoPartida[i]);
}
sizeArray=sizeof(conjuntoLlegada);
printf("\nEl conjunto 2 es:\n");
for(int i=0;i<sizeArray;i++){
printf("%c, ",conjuntoLlegada[i]);
}
}
int main(){
int conjuntoPartida[4] = {1,2,3,8};
char conjuntoLlegada[4] = {'a','b','j','k'};
int elementoDePrimerConjunto;
char elementoDeSegundoConjunto;
mostrarConjuntos(conjuntoPartida,conjuntoLlegada);
establecerRelaciones(conjuntoPartida, conjuntoLlegada);
getch();
}