
¿Como ordeno según el sexo?
Publicado por Gabriel (10 intervenciones) el 16/03/2017 14:38:13
Tengo un problema al querer ordenar el saldo de Mayor a Menor, pero solo de las Mujeres, el codigo me da error, estuve cambiándolo constantemente para ver si funcionaba de alguna manera, pero se ve que algo estoy haciendo mal.
La Funcion :
El Codigo completo :
La Funcion :
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
void ordenamiento_saldo_mujeres(struct CLIENTES mujeres[],int NUM){
struct CLIENTES AUX;
int k,j;
for(k=0;k<NUM;k++){
for(j=0;j<NUM;j++)
if(mujeres[j].sexo == 'F'){
if(mujeres[j].saldo > mujeres[j+1].saldo){
AUX = mujeres[j];
mujeres[j] = mujeres[j+1];
mujeres[j+1] = AUX;
}
}
}
printf("Las mujeres con los mejores salarios son : ");
printf("\n");
for(k = N ; k<0 ; k--){
printf("Nombre : %s ",mujeres[k].nombre);
printf("\n");
printf("Saldo : %i",mujeres[k].saldo);
printf("\n");
}
return 0;
}
El Codigo completo :
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define N 5
struct CLIENTES{
char nombre[30];
char sexo;
int saldo;
};
void ingresar(struct CLIENTES[],int);
void ordenamiento_saldo_mujeres(struct CLIENTES[],int);
int main(){
struct CLIENTES clientes[N];
int opcion;
while (opcion != 3){
printf("Ingrese una Opcion : ");
printf("\n\n");
printf("Opcion 1: Ingresar los datos de los clientes :\n");
printf("\n\n");
printf("Opcion 2 : Mostrar saldo de mujeres de Mayor a Menor :");
printf("\n\n");
printf("Opcion 3 : Salir! :");
printf("\n\n");
scanf("%i", &opcion);
fflush(stdin);
switch (opcion){
case 1: ingresar(clientes,N); break;
case 2: ordenamiento_saldo_mujeres(clientes,N);break;
case 3 : break;
}
}
return 0;
}
void ingresar(struct CLIENTES client[],int NUM) {
int i;
for (i = 0; i<N; i++) {
printf("Ingrese su nombre : ");
scanf("%s",&client[i].nombre);
printf("\n");
fflush(stdin);
printf("Ingrese su Sexo : ");
scanf("%s",&client[i].sexo);
printf("\n");
printf("Ingrese su Saldo :");
scanf("%i",&client[i].saldo);
fflush(stdin);
printf("\n");
}
}
void ordenamiento_saldo_mujeres(struct CLIENTES mujeres[],int NUM){
struct CLIENTES AUX;
int k,j;
for(k=0;k<NUM;k++){
for(j=0;j<NUM;j++)
if(mujeres[j].sexo == 'F'){
if(mujeres[j].saldo > mujeres[j+1].saldo){
AUX = mujeres[j];
mujeres[j] = mujeres[j+1];
mujeres[j+1] = AUX;
}
}
}
printf("Las mujeres con los mejores salarios son : ");
printf("\n");
for(k = N ; k<0 ; k--){
printf("Nombre : %s ",mujeres[k].nombre);
printf("\n");
printf("Saldo : %i",mujeres[k].saldo);
printf("\n");
}
return 0;
}
Valora esta pregunta


0