#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int random();
void leerVector(int v[], int n);
void imprimirVector(int v[], int n);
int valorMasRepetido(int v[], int n);
void indicesValor(int v[], int n, int valor);
int main()
{
srand(time(NULL));
int v[20];
leerVector(v, 20);
cout << "\nVector: "; imprimirVector(v, 20);
int repetido = valorMasRepetido(v, 20);
cout << "\nValor mas repetido: " << repetido;
cout << "\nIndices: "; indicesValor(v, 20, repetido);
cout << endl;
return 0;
}
int random()
{
return rand() % 10 + 1;
}
void leerVector(int v[], int n)
{
for (int i = 0; i < n; i++)
v[i] = random();
}
void imprimirVector(int v[], int n)
{
for (int i = 0; i < n; i++)
cout << v[i] << " ";
}
int valorMasRepetido(int v[], int n)
{
int max, count = 0, temp = 0;
for (int i = 0; i < n; i++)
{
temp = 0;
for (int j = 0; j < n; j++)
{
if (v[i] == v[j])
temp++;
}
if (temp > count)
{
count = temp;
max = v[i];
}
}
return max;
}
void indicesValor(int v[], int n, int valor)
{
for (int i = 0; i < n; i++)
if (v[i] == valor)
cout << i << " ";
}