problema con un string
Publicado por rodrigo (7 intervenciones) el 08/06/2019 08:05:14
el problema esta en el caso 5 ya que al ejecutar y posteriormente mostrar me marca los numeros que elimino con 0, y lo que yo necesito es que elimine el espacio.
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*Se tiene una serie de numero que son capturados, se requiere un algoritmo que realize las siguientes funciones
1 elimine duplicados
2 Muestra la serie
3 ordene los numeros (menor a mayor).
4 Busque un valor determinado e indicar cuantas veces se repite en el arreglo.
5 Eliminar numeros impares, peor nolos numeros que teminan en 4.
6 Convertir un numero a letra
7 Terminar
Todas las funciones pueden ser ejecutadas hasta que se le indique la funcion terminar
La funcion capturar solo se ejecuta una vez */
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int n;
int numeros;
int a[100];
int i=0;
int c=0;
int d=0;
int x, pos, aux;
int j;
int k;
int y, opcion;
int contador=0;
int b[100];
int enc=0;
int res;
using namespace std;
int main(int argc, char * argv[])
{
printf ("dame el tamano del arreglo: ");
scanf ("%i", &n);
do
{
printf ("dame el numero: ");
scanf ("%i", &numeros);
a[i]=numeros;
i++;
}while (i<n);
do
{
printf( "\n 1. Elimimar duplicados.", 163 );
printf( "\n 2. Mostrar la serie.", 163 );
printf( "\n 3. Ordenar numeros.", 163 );
printf( "\n 4. Buscar un numero.", 163);
printf( "\n 5. Mostrar impares.", 163 );
printf( "\n 6. Buscar numero y convertirlo a letra", 163 );
printf( "\n 7. Terminar", 163);
printf( "\n\n Introduzca opci%cn (1-7): ", 162 );
scanf( "%d", &opcion );
/* Inicio del anidamiento */
switch ( opcion )
{
case 1: for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
for(k=j;k<n-1;k++)
a[k]=a[k+1];
n=n-1;
j=i;
}
break;
case 2: printf("\n Tu serie es: \n");
for(i=0; i<n; i++)
{
printf("%i \n", a[i] );
}
break;
case 3: for (i=0; i<n; i++)
{
pos = i;
aux = a[i];
while((pos>0)&&(aux<a[pos-1]))
{
a[pos] = a[pos-1];
pos--;
}
a[pos] = aux;
}
break;
case 4: /*printf ("Que numero quieres buscar: ");
scanf ("%i", &x);
i=0;
do
{
if (a[i]==x)
{
printf ("encontre el numero %i en el arreglo.\n", x);
}
else (a[i]!=x); printf ("No encontre el numero en el arreglo. \n");
i++;
}while (i<n); */
printf ("Que numero quieres buscar: " );
scanf ("%i", &x);
i=0;
do
{
if(a[i]==x)
{
for (i=0;i<n;i++)
{
for (i=0;i<n;i++)
{
if (x==a[i])
{
contador++;
}
}
printf("El numero se repite %i veces en tu arreglo\n",contador);
}
}
if(enc==0)
{
printf("\n No esta en el arreglo \n ");
}
i++;
}while(i<n);
break;
case 5: for( c=0; c<n; c++ ) //Limpia arreglo tmp
{
b[c]= '\0';
}
for (i=0; i<n; i++)
{
res = (a[i]%2);
if (res != 0)
{
b[d]=a[i];
d++;
}
res = (a[i]%10);
if (res == 4)
{
b[d]=a[i];
d++;
}
} //Limpia arreglo original
for( c=0; c<n; c++)
{
a[c]= '\0';
} //Envía datos de tmp a original
for (i=0; i<d; i++)
{
a[i]=b[i];
}
i++;
break;
case 6:
cout<<"Ingresa el numero"<<endl;
cin>>x;
if((x<1)||(x>999)) cout<<"INGRESA UN NUMERO DEL 1 AL 999\n";
else
{
if(x>=900) {cout<<"NOVECIENTOS " ;x=x-900;}
else if(x>=800) {cout<<"OCHOCIENTOS " ;x=x-800;}
else if(x>=700) {cout<<"SETECIENTOS " ;x=x-700;}
else if(x>=600) {cout<<"SEISCIENTOS " ;x=x-600;}
else if(x>=500) {cout<<"QUINIENTOS " ;x=x-500;}
else if(x>=400) {cout<<"CUATROCIENTOS " ;x=x-400;}
else if(x>=300) {cout<<"TRESCIENTOS " ;x=x-300;}
else if(x>=200) {cout<<"DOSCIENTOS " ;x=x-200;}
else if(x>100) {cout<<"CIENTO " ;x=x-100;}
else if(x==100) {cout<<"CIEN" ;x=x-100;}
if(x>90) {cout<<"NOVENTA Y " ;x=x-90; }
if(x==90) {cout<<"NOVENTA" ;x=x-90; }
if(x>80) {cout<<"OCHENTA Y " ;x=x-80; }
if(x==80) {cout<<"OCHENTA" ;x=x-80; }
if(x>70) {cout<<"SETENTA Y " ;x=x-70; }
if(x==70) {cout<<"SETENTA" ;x=x-70; }
if(x>60) {cout<<"SESENTA Y " ;x=x-60; }
if(x==60) {cout<<"SESENTA" ;x=x-60; }
if(x>50) {cout<<"CINCUENTA Y " ;x=x-50; }
if(x==50) {cout<<"CINCUENTA" ;x=x-50; }
if(x>40) {cout<<"CUARENTA Y " ;x=x-40; }
if(x==40) {cout<<"CUARENTA" ;x=x-40; }
if(x>30) {cout<<"TREINTA Y " ;x=x-30; }
if(x==30) {cout<<"TREINTA" ;x=x-30; }
if(x>20) {cout<<"VEINTI " ;x=x-20; }
if(x==20) {cout<<"VEINTE" ;x=x-20; }
if(x>=16) {cout<<"DIECI " ;x=x-10; }
else if(x==15) {cout<<"QUINCE" ;x=x-15; }
else if(x==14) {cout<<"CATORCE" ;x=x-14; }
else if(x==13) {cout<<"TRECE" ;x=x-13; }
else if(x==12) {cout<<"DOCE" ;x=x-12; }
else if(x==11) {cout<<"ONCE" ;x=x-11; }
else if(x==10) {cout<<"DIEZ" ;x=x-10; }
if(x==9) {cout<<"NUEVE" ;x=x-9; }
if(x==8) {cout<<"OCHO" ;x=x-8; }
if(x==7) {cout<<"SIETE" ;x=x-7; }
if(x==6) {cout<<"SEIS" ;x=x-6; }
else if(x==5) {cout<<"CINCO" ;x=x-5; }
else if(x==4) {cout<<"CUATRO" ;x=x-4; }
else if(x==3) {cout<<"TRES" ;x=x-3; }
else if(x==2) {cout<<"DOS" ;x=x-2; }
else if(x==1) {cout<<"UNO" ;x=x-1; }
}
cout<<endl;
cin.ignore();
break;
}
/* Fin del anidamiento */
} while ( opcion != 7 );
return 0;
}
Valora esta pregunta


0