example
/ * To give you a guide to do the workshop lab 5 and 5, made this year. ;)
if something goes wrong they are by the copy-paste ... review it and fix it!
* /
< iostream> # include using namespace std
;
void read (int v [], int n) {court
<<"Ingrese los valores del vector:\n";
for (int i = 0; i < n;i++)
cin>> v [i];}
void print (int v [], int n) {
for (int i = 0; i < n;i++)
court << v[i]<<">
}
contarApariciones int (int v [], int n, int value) {int
cont = 0;
for (int i = 0 ; i < n;i++)
if (value == v [i])
cont + +;
return cont;
}
int calcularModa (int v [], int n) {
int mode = v [0] = 1 contmoda, cont;
for (int i = 0; i < n;i++){
contarApariciones cont = (v, n, v [i]);
if (cont> contmoda) {
contmoda = cont;
mode = v [i];
}} return
fashion;
} void pause ( ) {
<<"\n\n";
court system ("pause");
} int main () {int
vector [5], size = 5, mode;
read (vector , size);
print (vector, size);
mode = calcularModa (vector, size);
<<"\nLa moda es "<< moda;
court <<" y aparece"<< contarApariciones(vector,tamano,moda)<<" veces";
court pause ();
return 0;}
0 comments:
Post a Comment