
Mi matriz solo imprime ceros??
Publicado por Marta (7 intervenciones) el 12/12/2016 02:23:06
Hola! Sí, soy la misma pesada de antes xD. Ya he terminado el ejercicio y no me da ningún error, pero cuando en el menú (después de introducir los datos) elijo la opción 2 para imprimir la matriz, esta solo imprime ceros...
Si alguien fuera tan amable de ayudarme, le estaría muy agradecida. Me gustaría terminar con este dichoso ejercicio de una vez xD.
Si alguien fuera tan amable de ayudarme, le estaría muy agradecida. Me gustaría terminar con este dichoso ejercicio de una vez xD.
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define MAXMEDICIONES 5
#define NUMPIPETAS 3
void leerMediciones(int m[MAXMEDICIONES][NUMPIPETAS]);
void imprimirMediciones(int m[MAXMEDICIONES][NUMPIPETAS]);
void calcularPromedio (int m[MAXMEDICIONES][NUMPIPETAS]);
void calcularDesviacionTipica(int m[MAXMEDICIONES][NUMPIPETAS]);
void calcularErrorAleatorio(int m[MAXMEDICIONES][NUMPIPETAS]);
void buscarAnomalos(int m[MAXMEDICIONES][NUMPIPETAS]);
void main(){
int matriz[MAXMEDICIONES][NUMPIPETAS];
int op;
while(op!=0){
printf("-------------MENU------------\n\n");
printf("1.- Introducir las mediciones\n");
printf("2.- Imprimir mediciones\n");
printf("3.- Calcular error aleatorio\n");
printf("4.- Buscar valores anomalos\n");
printf("0.- Salir\n\n");
printf("Elige una opcion: ");
scanf("%d",&op);
printf("----------------------------\n");
switch(op)
{
case 1: leerMediciones(matriz);
break;
case 2: imprimirMediciones(matriz);
break;
case 3: calcularPromedio (matriz);
calcularDesviacionTipica(matriz);
calcularErrorAleatorio(matriz);
break;
case 4: buscarAnomalos(matriz);
break;
default: printf("Opcion no valida. Por favor, vuelva a elegir. \n\n");
}
}
}
void leerMediciones(int m[MAXMEDICIONES][NUMPIPETAS]){
int i,j;
printf("Introduzca los elementos de la matriz %dx%d\n", MAXMEDICIONES, NUMPIPETAS);
for(i=0;i<MAXMEDICIONES;i++){
for(j=0;j<NUMPIPETAS;j++){
printf("Fila %d - Columna %d: ", i,j);
scanf("%f", &m[i][j]);
}
}
}
void imprimirMediciones(int m[MAXMEDICIONES][NUMPIPETAS]){
int i,j;
printf("Impresion de la Matriz: \n");
for(i=0;i<MAXMEDICIONES;i++){
for(j=0;j<NUMPIPETAS;j++){
printf("%.4f", m[i][j]);
}
printf("\n");
}
}
void calcularPromedio (int m[MAXMEDICIONES][NUMPIPETAS]){
int i,j;
float medias[NUMPIPETAS];
for(j=0;j<NUMPIPETAS;j++){
medias[j]=0;
for(i=0;i<MAXMEDICIONES;i++){
medias[j]= medias[j] + m[i][j];
}
medias[j]= medias[j]/MAXMEDICIONES;
}
}
void calcularDesviacionTipica(int m[MAXMEDICIONES][NUMPIPETAS]){
int i,j;
float suma, medias[j], varianza[NUMPIPETAS], desviacion_tipica[NUMPIPETAS];
/*Calculamos la desviacion tipica*/
for(j=0;j<NUMPIPETAS;j++){
suma=0;
for(i=0;i<MAXMEDICIONES;i++){
{
suma = suma + pow((m[i][j] - medias[j]), 2);
}
}
}
varianza[NUMPIPETAS] = suma/4;
desviacion_tipica[NUMPIPETAS] = sqrt(varianza[NUMPIPETAS]);
printf("Desviacion tipica = %.2f\n", desviacion_tipica[NUMPIPETAS]);
getch();
}
void calcularErrorAleatorio(int m[MAXMEDICIONES][NUMPIPETAS]){
float error_aleatorio[NUMPIPETAS], desviacion_tipica[NUMPIPETAS];
error_aleatorio[NUMPIPETAS] = desviacion_tipica[NUMPIPETAS]/sqrt(5);
printf("Error aleatorio = %.2f\n", error_aleatorio[NUMPIPETAS]);
getch();
}
void buscarAnomalos(int m[MAXMEDICIONES][NUMPIPETAS]){
//buscar numeros mayores que 1 en la primera columna
//mayores que 0.2 en la segunda columna y que 0.02 en la tercera columna
int i,j=0;
float enc;
enc=0; /*Los datos son correctos, no hay numeros anomalos*/
/*Vamos a hacer un recorrido para calcular los valores anomalos*/
while(!enc && j < NUMPIPETAS)
{
i=0;
while(!enc && i < MAXMEDICIONES)
{
if(j == 0 && m[i][j] > 1.0001)
{
enc = 1;
printf("Hay al menos un valor anomalo en los datos proporcionados.\n\n\n");
}
else if (j == 1 && m[i][j] > 0.2001)
{
enc = 1;
printf("Hay al menos un valor anomalo en los datos proporcionados.\n\n\n");
}
else if (j == 2 && m[i][j] > 0.0201)
{
enc = 1;
printf("Hay al menos un valor anomalo en los datos proporcionados.\n\n\n");
}
else
{
enc = 0;
printf("Los valores introducidos son correctos.\n\n\n");
}
i++;
}
j++;
}
return enc;
}
Valora esta pregunta


0