Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- - Practica 1
- - heyshir
- */
- #include <iostream>
- using namespace std;
- const int MAXNUM = 20;
- const int MAXCOMP = 10;
- struct numeros {
- int n;
- int r;
- };
- numeros num[MAXNUM];
- numeros comp[MAXCOMP];
- int comparar_introducido(int &x, int &c);
- int mas_repetido ();
- int main() {
- int valor = 0;
- bool ok = false;
- for (int a = 1; a <= MAXNUM; a++) {
- ok = 0;
- while (ok != true) {
- cout << "Introduca el valor numero " << a << endl;
- cout << "--> ";
- cin >> valor;
- if ((valor >= 1) and (valor <= MAXCOMP)) {
- num[a].n = valor;
- num[a].r = 0;
- ok = true;
- }
- else {
- cout << "**El valor es erroneo**" << endl;
- }
- }
- }
- int x = 0;
- ok = false;
- while (ok != true) {
- cout << "Introduzca el numero a comparar" << endl;
- cin >> x;
- if ((x >= 1) and (x <=10)) {
- ok = true;
- }
- else {
- cout << "**El valor es erroneo**" << endl;
- }
- }
- int c = 0;
- comparar_introducido (x, c);
- cout << "El numero " << x << " aparece " << c << " veces en la lista" << endl;
- mas_repetido ();
- //system ("pause");
- }
- int comparar_introducido(int &x, int &c) {
- for (int a = 1; a <= MAXNUM; a++) {
- if (x == num[a].n) {
- c++;
- }
- }
- }
- int mas_repetido () {
- for (int e = 1; e <= MAXCOMP; e++) { //inicializamos el segundo vector
- comp[e].n = e;
- comp[e].r = 0;
- }
- for (int e = 1; e <= MAXCOMP; e++) {
- for (int a = 1; a <= MAXNUM; a++) {
- if (comp[e].n == num[a].n) {
- int c = 0;
- comparar_introducido(comp[e].n, c);
- comp[e].r = c;
- }
- }
- }
- int repe = 0, y;
- for (int a = 1; a <= MAXCOMP; a++) {
- if (comp[a].r > repe) {
- repe = comp[a].r;
- y = comp[a].n;
- }
- }
- cout << "El valor ams repetido es " << y << " con " << repe << " veces" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement