I am beginning to study the c language and I need some help with this exercise.
It's almost all done and just need to compile it and see if it works, but I'm not sure how to do the last part.
When option 4 of the menu is chosen, the program must take a tour of the matrix (I think it is a tour) and check if there are values in the first column that are greater than 1, in the second column they are higher to 0.2 and in the third column that are greater than 0.02. If you find these values, a message will appear that indicates that there is at least one anomalous value, otherwise a message will appear indicating that the values you have entered are correct.
This is my code:
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define NUMPIPETAS 3
#define MAXMEDICIONES 5
void leerMediciones(int m[NUMPIPETAS][MAXMEDICIONES]);
void imprimirMediciones(int m[NUMPIPETAS][MAXMEDICIONES]);
void calcularPromedio (int m[NUMPIPETAS][MAXMEDICIONES]);
void calcularDesviacionTipica(int m[NUMPIPETAS][MAXMEDICIONES]);
void calcularErrorAleatorio(int m[NUMPIPETAS][MAXMEDICIONES]);
void buscarAnomalos(int m[NUMPIPETAS][MAXMEDICIONES]);
void main(){
int matriz[NUMPIPETAS][MAXMEDICIONES];
int m[NUMPIPETAS][MAXMEDICIONES], sumaColumnas[NUMPIPETAS];
float x[15];
int opc=0;
char choice;
do {
leerMediciones(m);
system("cls");
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",&opc);
printf("----------------------------\n");
switch(opc)
{
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");
}
}while(choice !=4);
imprimirMatriz(matriz);
}
void leerMediciones(int m[NUMPIPETAS][MAXMEDICIONES]){
int i,j;
printf("Introduzca los elementos de la matriz %dx%d\n",NUMPIPETAS,MAXMEDICIONES);//deberia poner aqui i y j en vez de numpipetas y maxmediciones??
for(i=0;i<NUMPIPETAS;i++){
for(j=0;j<MAXMEDICIONES;j++){
printf("Fila %d - Columna %d: ", i,j);
scanf("%d", &m[i][j]);
}
}
}
void imprimirMediciones(int m[NUMPIPETAS][MAXMEDICIONES]){
int i,j;
printf("Impresion de la Matriz:\n");
for(i=0;i<NUMPIPETAS;i++){
for(j=0;j<MAXMEDICIONES;j++){
printf("%d ", m[i][j]);
}
printf("\n");
}
}
void calcularPromedio (int m[NUMPIPETAS][MAXMEDICIONES]){
int i,j;
float sumaTotal, sumaColumnas[NUMPIPETAS], suma, media;
/*Ahora calculamos la media*/
/*Pero primero hacemos la suma total*/
sumaTotal=0;
for(i=0;i<NUMPIPETAS;i++){
for(j=0;j<MAXMEDICIONES;j++){
sumaTotal = sumaTotal + m[NUMPIPETAS][MAXMEDICIONES];
}
}
/*Calculamos la suma de cada columna*/
for(j=0;j<MAXMEDICIONES;j++){
suma = 0;
for(i=0;i<NUMPIPETAS;i++){
suma = suma + m[NUMPIPETAS][MAXMEDICIONES];
}
sumaColumnas[j] = suma;
/*Ahora hacemos la media de cada columna*/
media = suma/5;
}
}
void calcularDesviacionTipica(int m[NUMPIPETAS][MAXMEDICIONES]){
int i,j;
float suma1=0, media, varianza, desviacion_tipica;
int x[i];
/*Calculamos la desviacion tipica*/
for(i=0;i<NUMPIPETAS;i++){
for(j=0;j<MAXMEDICIONES;j++){
{
suma1 = suma1 + pow((media - x[i]), 2);
}
}
}
varianza = suma1 / 4;
desviacion_tipica = sqrt(varianza);
printf("Desviacion tipica = %.2f\n", desviacion_tipica);
getch();
}
void calcularErrorAleatorio(int m[NUMPIPETAS][MAXMEDICIONES]){
float error_aleatorio, desviacion_tipica;
error_aleatorio = desviacion_tipica/sqrt(5);
printf("Error aleatorio = %.2f\n", error_aleatorio);
getch();
}
void buscarAnomalos(int m[NUMPIPETAS][MAXMEDICIONES]){
//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;
/*Vamos a hacer un recorrido para calcular los valores anomalos*/
for(j=0;j<MAXMEDICIONES;j++){
for(i=0;i<NUMPIPETAS;i++){
if
}
}
}