Ejercicio de arreglos con subprogramas (Eliminar un vector de la posicion)
Publicado por Brayan (8 intervenciones) el 03/12/2016 07:11:55
Buenas noches, alguien podría ayudarme con este ejercicio? (Adjunto imagen), es que tengo el ejercicio de esta manera ( pego el código), y no me funciona, lega a una parte que me dice que "El programa.exe dejó de funcionar" Agradecería mucho de su gran ayuda! Gracias de igual manera!!
Dejaré esta version con un comentario (El void de imprimir ahora no esta, ya que lo metí en la función main):
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
#include <iostream>
using namespace std;
int i, j, val, vec2[100], n;
float vec[100];
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void crear (float vec[100], int n){
int i;
for (i=1; i<=n; i++){
cout<<"ingrese un valor en la posicion"<<i; cin>>vec[i];
}
}
void valoresrepetidos (float vec[100], int n, int vec2[100]){
int i, j, cont;
for (i=1; n-1; i++){
cont=1;
for (j=i+1; i<=n; i++){
if (vec[i]=vec[j]){
cont=cont+1;
}
}
vec2[i]=cont;
}
}
float valoresmasrepetidos (int vec2[100], int n, float vec[100]){
int mayor=vec2[1], valor;
for (i=2; i<=n; i++){
if (vec2[i]>mayor){
mayor=vec[i];
valor=vec[i];
}
}
return valor;
}
void eliminar (float vec[100], int n, int val){
int i, j;
for (i=1; n-1; i++){
if (vec[i]=val){
for (j=i; n-1; j++){
vec[j]= vec[j+1];
}
n=n-1;
}
}
if (val=vec[i]){
n=n-1;
}
}
void imprimir (float vec[100], int n){
int i;
for (i=1; i<=n; i++){
cout<<vec[i];
}
}
int main(int argc, char** argv) {
cout<<"Ingrese el tamaño del vector: "; cin>>n;
crear (vec, n);
valoresrepetidos (vec, n, vec2);
valoresmasrepetidos (vec2, n, vec);
eliminar (vec, n, val);
imprimir (vec, n);
return 0;
}
Dejaré esta version con un comentario (El void de imprimir ahora no esta, ya que lo metí en la función main):
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
#include <iostream>
using namespace std;
int i, j, val, vec2[100], n;
float vec[100];
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void crear (float vec[100], int n){
int i;
for (i=1; i<=n; i++){
cout<<"ingrese un valor en la posicion"<<i; cin>>vec[i];
}
}
void valoresrepetidos (float vec[100], int n, int vec2[100]){
int i, j, cont;
for (i=1; n-1; i++){
cont=1;
for (j=i+1; i<=n; i++){
if (vec[i]=vec[j]){
cont=cont+1;
}
}
vec2[i]=cont;
}
}
float valoresmasrepetidos (int vec2[100], int n, float vec[100]){
int mayor=vec2[1], valor;
for (i=2; i<=n; i++){
if (vec2[i]>mayor){
mayor=vec[i];
valor=vec[i];
}
}
return valor;
}
void eliminar (float vec[100], int n, int val){
int i, j;
for (i=1; n-1; i++){
if (vec[i]=val){
for (j=i; n-1; j++){
vec[j]= vec[j+1];
}
n=n-1;
}
}
if (val=vec[i]){
n=n-1;
}
}
/*void imprimir (float vec[100], int n){
int i;
for (i=1; i<=n; i++){
cout<<vec[i];
}
}*/
int main(int argc, char** argv) {
cout<<"Ingrese el tamaño del vector: "; cin>>n;
for (i=1; i<=n; i++){
cout<<vec[i];
}
crear (vec, n);
valoresrepetidos (vec, n, vec2);
valoresmasrepetidos (vec2, n, vec);
eliminar (vec, n, val);
/* imprimir (vec, n);*/
return 0;
}
Valora esta pregunta
0