Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- using namespace System;
- void generar_datos(int *Vnumeros, int nelementos)
- {
- Random r;
- for (int i = 0; i < nelementos; i++)
- Vnumeros[i] = r.Next(1, 101);
- }
- void imprimir_datos(int *Vnumeros, int nelementos)
- {
- int i;
- cout << "impresion de datos generados\n";
- for (i = 0; i < nelementos; i++)
- cout << Vnumeros[i] << endl;
- }
- int mayor_elemento(int *Vnumeros, int nelementos)
- {
- int mayor, i;
- mayor = Vnumeros[0];
- for (i = 1; i < nelementos; i++)
- if (Vnumeros[i]>mayor)
- mayor = Vnumeros[i];
- return mayor;
- }
- int menor_elemento(int *Vnumeros, int nelementos)
- {
- int menor, i;
- menor = Vnumeros[0];
- for (i = 1; i < nelementos; i++)
- if (Vnumeros[i]<menor)
- menor = Vnumeros[i];
- return menor;
- }
- int buscar_elemento(int *Vnumeros, int nelementos, int datobuscado)
- {
- int posicion, i;
- posicion = -1;
- for (i = 0; i < nelementos; i++)
- if (Vnumeros[i] == datobuscado)
- posicion = i;
- return posicion;
- }
- int contar_repeticiones(int *Vnumeros, int nelementos, int datobuscado)
- {
- int contador, i;
- contador = 0;
- for (i = 0; i < nelementos; i++)
- if (Vnumeros[i] == datobuscado)
- contador++;
- return contador;
- }
- void main()
- {
- int *Vnumeros;
- int nelementos,datobuscado;
- do
- {
- cout << "ingrese cantidad de elementos: "; cin >> nelementos;
- } while (nelementos < 1 || nelementos>25);
- Vnumeros = new int[nelementos];
- generar_datos(Vnumeros, nelementos);
- imprimir_datos(Vnumeros, nelementos);
- cout << "el mayor elemento es " << mayor_elemento(Vnumeros, nelementos) << endl;
- cout << "el menor elemento es " << menor_elemento(Vnumeros, nelementos) << endl;
- cout << "ingrese dato a buscar: "; cin >> datobuscado;
- if (buscar_elemento(Vnumeros, nelementos, datobuscado) != -1)
- cout << "el dato se encuentra en " << buscar_elemento(Vnumeros, nelementos, datobuscado) << endl;
- else
- cout << "el dato no se encuentra\n";
- cout << "ingrese dato a buscar: "; cin >> datobuscado;
- cout << "el dato se repite : " << contar_repeticiones(Vnumeros, nelementos, datobuscado);
- delete[]Vnumeros;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement