Dev - C++ - Problema al calcular la moda

 
Vista:

Problema al calcular la moda

Publicado por Sodaer (5 intervenciones) el 19/03/2013 05:10:40
Como todos sabemos la moda es un termino que se utiliza en Estadística para saber cual es el numero que mas se repite.
Mi programa ordena números aleatorios y arroja la media la mediana y la moda y al estarlo corriendo me di cuenta que si hay mas de un número que se repite mas, entonces imprime el ultimo que se repitió en vez de los 2 o 3 que se repitieron aquí esta el código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main (void)
{
 clrscr();
 int arreglo[10],x,cont,mod;
 float Prom;
 randomize();
 cout<<"***Metodo Burbuja, Media,mediana,moda***\a"<<endl;
 for (int i=0;i<10;i++)
 {
  arreglo[i]=random(10)+1;
  cout<<arreglo[i]<<" ";
 }
 getch();
 for(int j=0;j<10;j++)
  {
   for(int k=0;k<10;k++)
   {
    if(arreglo[j]>arreglo[k])
    {
     x=arreglo[k];
     arreglo[k]=arreglo[j];
     arreglo[j]=x;
    }
   }
  }
 cout<<"\n";
 for(int l=9;l>=0;l--)
 {
  cont=0;
 
  cout<<arreglo[l]<<" ";
  for(int a=9;a>=0;a--)
  {
   if(arreglo[l]==arreglo[a])
   {
    cont++;
   }
   if(cont>=2)
   {
    mod=arreglo[l];
   }
  }
 }
 for(int b=9;b>=0;b--)
 {
 Prom=Prom+arreglo[b];
 }
 Prom=Prom/10;
 cout<<"\n\20 Media: "<<Prom;
 cout<<"\n\20 Mediana: "<<arreglo[5]<<" "<<arreglo[4];
 cout<<"\n\20 Moda: "<<mod;
 
 getch();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 46
Ha disminuido 1 puesto en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Problema al calcular la moda

Publicado por manuel_venezuela (62 intervenciones) el 21/03/2013 19:48:20
viendo tu problema...no estoy muy seguro..que asi se calcule la mediana,..el valor en el medio ,dado un arreglo ordenado,..y la moda..---

de todas maneras te voy a enviar un ejercicio resuelto en deitel&& deitel, donde hay una funcion que calcula...la moda y la mediana..

-----
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*this program introduces the topic of survey data analysis
it computes the mean, median, and mode of the data*/
 
#include<stdio.h>
#define SIZE 99
 
void mean(int []);
void median(int []);
void mode(int [],int []);
void bubbleSort(int []);
void printArray(int []);
 
main()
{
	int frequency[10]={0},
	response[SIZE]={6,7,8,9,8,7,8,9,8,9,
					7,8,9,5,9,8,7,8,7,8,
					6,7,8,9,3,9,8,7,8,7,
					7,8,9,8,9,8,9,7,8,9,
					6,7,8,7,8,7,9,8,9,2,
					7,8,9,8,9,8,9,7,5,3,
					5,6,7,2,5,3,9,4,6,4,
					7,8,9,6,8,7,8,9,7,8,
					7,4,4,2,5,3,8,7,5,6,
					4,5,6,1,6,5,7,8,7};
 
	mean(response);
	median(response);
	mode(frequency,response);
	return 0;
}
 
void mean(int answer[])
{
	int j, total=0;
 
	printf("%s\n%s\n%s\n","********","mean","********");
 
	for(j=0;j<=SIZE-1;j++)
		total+=answer[j];
 
	printf("The mean is the average value of the data\n"
		   "items. the mean is equal to the total of\n"
		   "all the data items divided by the number\n"
		   "of data items(%d).The mean value for\n"
		   "this run is: %d / %d = %.4f\n\n",
		   SIZE,total,SIZE,(float) total / SIZE);
 
}
 
void median(int answer[])
{
	printf("\n%s\n%s\n%s\n%s",
		"********","Median","********",
		"The unsorted array responses is");
 
	printArray(answer);
	bubbleSort(answer);
	printf("\n\nThe sorted array is");
	printArray(answer);
	printf("\n\nThe median is element %d of\n"
		"the sorted %d element array.\n"
		"For this run the median is %d\n\n",
		SIZE / 2,SIZE,answer [SIZE /2 ]);
 
 
}
 
void mode(int freq[], int answer[])
{
 
	int rating,j,h,largest=0,modeValue=0;
 
	printf("\n%s\n%s\n%s\n%s",
		"********", "Mode", "********");
 
	for(rating=1;rating<=9;rating++)
		freq[rating]=0;
 
	for(j=0;j<=SIZE-1;j++)
		++freq[answer[j]];
 
	printf("%s%11s%19s\n\n%54s\n%54s\n\n",
		"Response", "frequency","histogram",
		"1   1   2   2","5   0   5   0   5");
 
	for(rating=1;rating<=9;rating++){
		printf("%8d%11d       ",rating,freq[rating]);
 
	if(freq[rating] > largest){
 
	largest= freq[rating];
	modeValue=rating;
	}
 
	for(h=1;h<=freq[rating];h++)
		printf("*");
 
	printf("\n");
	}
 
	printf("The mode is the most frequent value.\n"
		"For this run the mode is %d which ocurred"
		"%d times.\n",modeValue,largest);
 
 
}
 
void bubbleSort(int a[])
{
	int pass,i,hold;
 
 
	for(pass=1;pass<=SIZE -1;pass++)
 
		for(i=0;i<=SIZE -2;i++)
			if(a[i]>a[i+1]){
			hold=a[i];
 
			a[i]=a[i+1];
 
			a[i+1]=hold;
 
 
 
			}
 
 
}
 
void printArray(int a[])
{
	int j;
 
	for(j=0;j<=SIZE-1;j++){
		if(j%20==0)
			printf("\n");
		printf("%2d",a[j]);
	}
 
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 46
Ha disminuido 1 puesto en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Problema al calcular la moda

Publicado por manuel_venezuela (62 intervenciones) el 21/03/2013 19:51:34
cualquier cosa....dime la urgencia y resolvems el problema..ok saludos desde venezuela
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema al calcular la moda

Publicado por Sodaer (5 intervenciones) el 21/03/2013 23:22:47
vale tio gracias, modifique mi codigo,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main (void)
{
 clrscr();
 int arreglo[10],f[10]={0},x,auxm,mod;
 float Prom;
 randomize();
 cout<<"moda,media,mediana"<<endl;
 for (int i=0;i<10;i++)
 {
  arreglo[i]=random(10)+1;
  cout<<arreglo[i]<<" ";
 }
 getch();
 for(int j=0;j<10;j++)
  {
   for(int k=0;k<10;k++)
   {
    if(arreglo[j]>arreglo[k])
    {
     x=arreglo[k];
     arreglo[k]=arreglo[j];
     arreglo[j]=x;
    }
   }
  }
 cout<<"\n";
 for(int l=9;l>=0;l--)
 {
  cout<<arreglo[l]<<" ";
  f[arreglo[l]]++;
 
  for(int m=9; m>=0;m--)
  {
   if (f[m]>auxm)
   {
    auxm=f[m];
    mod=m;
   }
 
  }
 }
 for(int b=9;b>=0;b--)
 {
 Prom=Prom+arreglo[b];
 }
 Prom=Prom/10;
 cout<<"\n\20 Media: "<<Prom;
 cout<<"\n\20 Mediana: "<<arreglo[5]<<" "<<arreglo[4];
 cout<<"\n\20 Moda: "<<mod;
 getch();
}

pero sigue sin salirme es el mismo error solo imprime 1 numero cuando la moda se repite ejemplo el la corrida
1 1 2 3 4 5 6 6 8 9
imprime solo el 1 en vez de 1 y 6
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema al calcular la moda

Publicado por emmanuel (4 intervenciones) el 13/04/2013 23:53:00
Hola amigo, de la forma que tienes el código nunca te va a imprimir los dos numero que pones de ejemplo o los que sean, te recomiendo que crees un arreglo y un contador y vayas guardando hay la cantidad de veces que se te repiten los números y ya al final decides cuales son los que tienes que imprimir con un for y un if.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema al calcular la moda

Publicado por Juan (1 intervención) el 18/04/2014 02:26:18
ME PODRÍAN AYUDAR CON ESTOS DOS PROGRAMAS PORFAVOR

1. Desarrollar un algoritmo en lenguaje C++ que lea un conjunto de datos enteros y determine cuál es el dato que más se repite

2. Un número entero es un número perfecto si la suma de sus factores, incluyendo el 1 (pero no el número mismo), da tal número. Por ejemplo, el 6 es un número perfecto porque 6=1+2+3.
a) Escriba una función perfecto que determine si el parámetro numero es un número perfecto.
b) Escriba un procedimiento que reciba un numero n, mayor que 1, y que escriba todos los números perfectos menores o iguales que n.
c) Utilice este procedimiento en un programa que le pida al usuario un número entero positivo y que encuentre e imprima todos los números perfectos entre 1 y ese número.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

AYUDENME POR FAVOR , NECESITO UN PROGRAMA QUE SAQUE LA MODA EN C , NO C++ , USANDO UN SOLO ARREGLO.

Publicado por Diana Zavala (1 intervención) el 30/04/2014 15:53:52
Hola chicos mi nombre es Diana Zavala , y tengo una tarea! es urgentee..!!!
necesito el programa de ,la MODA , en C ... NO C++ ,
y que la formula sea para un solo arreglo por favor , estudio informatica y depende mi nota de este programa..
Gracias
[email protected]
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 46
Ha disminuido 1 puesto en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

AYUDENME POR FAVOR , NECESITO UN PROGRAMA QUE SAQUE LA MODA EN C , NO C++ , USANDO UN SOLO ARREGLO.

Publicado por manuel castellano venezuela (62 intervenciones) el 30/04/2014 22:16:38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*this program introduces the topic of survey data analysis
it computes the mean, median, and mode of the data*/
 
#include<stdio.h>
#define SIZE 99
 
void mean(int []);
void median(int []);
void mode(int [],int []);
void bubbleSort(int []);
void printArray(int []);
 
main()
{
	int frequency[10]={0},
	response[SIZE]={6,7,8,9,8,7,8,9,8,9,
					7,8,9,5,9,8,7,8,7,8,
					6,7,8,9,3,9,8,7,8,7,
					7,8,9,8,9,8,9,7,8,9,
					6,7,8,7,8,7,9,8,9,2,
					7,8,9,8,9,8,9,7,5,3,
					5,6,7,2,5,3,9,4,6,4,
					7,8,9,6,8,7,8,9,7,8,
					7,4,4,2,5,3,8,7,5,6,
					4,5,6,1,6,5,7,8,7};
 
	mean(response);
	median(response);
	mode(frequency,response);
	return 0;
}
 
void mean(int answer[])
{
	int j, total=0;
 
	printf("%s\n%s\n%s\n","********","mean","********");
 
	for(j=0;j<=SIZE-1;j++)
		total+=answer[j];
 
	printf("The mean is the average value of the data\n"
		   "items. the mean is equal to the total of\n"
		   "all the data items divided by the number\n"
		   "of data items(%d).The mean value for\n"
		   "this run is: %d / %d = %.4f\n\n",
		   SIZE,total,SIZE,(float) total / SIZE);
 
}
 
void median(int answer[])
{
	printf("\n%s\n%s\n%s\n%s",
		"********","Median","********",
		"The unsorted array responses is");
 
	printArray(answer);
	bubbleSort(answer);
	printf("\n\nThe sorted array is");
	printArray(answer);
	printf("\n\nThe median is element %d of\n"
		"the sorted %d element array.\n"
		"For this run the median is %d\n\n",
		SIZE / 2,SIZE,answer [SIZE /2 ]);
 
 
}
 
void mode(int freq[], int answer[])
{
 
	int rating,j,h,largest=0,modeValue=0;
 
	printf("\n%s\n%s\n%s\n%s",
		"********", "Mode", "********");
 
	for(rating=1;rating<=9;rating++)
		freq[rating]=0;
 
	for(j=0;j<=SIZE-1;j++)
		++freq[answer[j]];
 
	printf("%s%11s%19s\n\n%54s\n%54s\n\n",
		"Response", "frequency","histogram",
		"1   1   2   2","5   0   5   0   5");
 
	for(rating=1;rating<=9;rating++){
		printf("%8d%11d       ",rating,freq[rating]);
 
	if(freq[rating] > largest){
 
	largest= freq[rating];
	modeValue=rating;
	}
 
	for(h=1;h<=freq[rating];h++)
		printf("*");
 
	printf("\n");
	}
 
	printf("The mode is the most frequent value.\n"
		"For this run the mode is %d which ocurred"
		"%d times.\n",modeValue,largest);
 
 
}
 
void bubbleSort(int a[])
{
	int pass,i,hold;
 
 
	for(pass=1;pass<=SIZE -1;pass++)
 
		for(i=0;i<=SIZE -2;i++)
			if(a[i]>a[i+1]){
			hold=a[i];
 
			a[i]=a[i+1];
 
			a[i+1]=hold;
 
 
 
			}
 
 
}
 
void printArray(int a[])
{
	int j;
 
	for(j=0;j<=SIZE-1;j++){
		if(j%20==0)
			printf("\n");
		printf("%2d",a[j]);
	}
 
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 46
Ha disminuido 1 puesto en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

AYUDENME POR FAVOR , NECESITO UN PROGRAMA QUE SAQUE LA MODA EN C , NO C++ , USANDO UN SOLO ARREGLO.

Publicado por manuel castellano venezuela (62 intervenciones) el 30/04/2014 22:33:24
ese programa esta muy bueno¡¡¡te calcula la moda , mediana y frecuencia.....ademas te ordena el vector¡¡

suerte....avisame
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

obtener la moda de un arreglo , el programa esta por funciones asi que solo pegare esa parte

Publicado por timoe (1 intervención) el 16/05/2015 01:46:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
float temp::moda(){
 
int moda;
moda=i;
	cout<<"\n\nLa moda es:";
for (int i=0;i<10;i++){
 
	if (c[i] == moda){
			cout<<"\t";
			cout<<i+1;
 
	}[
	}
 
}




espero puedan ayudarme
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar