Untitled
unknown
plain_text
4 years ago
981 B
14
Indexable
//12. Hacer un programa para eliminar los números duplicados de un vector.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void leerVector(float vec[], int n){
int i;
for(i=0;i<n; i++){
cout<<"Vec["<<i<<"] : ";
cin>>vec[i];
}
}
void imprimaVector(float vec[], int n){
int i;
cout << endl<<"El vector es --->>"<<endl;
for(i=0;i<n; i++){
cout<<vec[i]<<" " ;
}
}
void sinDup(float vec[], int &n){
int tam = n, i, j, k;
for(i = 0; i < n; i++){
for(j = i+1; j < tam; j++){
if(vec[i] == vec[j]){
k = j;
while(k < tam){
vec[k] = vec[k+1];
k++;
}
tam--;
j--;
}
}
}
n=tam;
}
int main(){
int n = 0;
float resul, vec[100];
cout<<"\nTamaño del vector: ";
cin>>n;
leerVector(vec, n);
imprimaVector(vec, n);
sinDup(vec, n);
return 0;
}
Editor is loading...