Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 9
- void media (const int resp[]);
- void mediana (int resp[]);
- void moda(int frec[], const int resp[]);
- void ordenamBurbuja(int a[]);
- void imprimeArreglo(const int a[]);
- int main(){
- int frecuencia[10]={0};
- int respuesta[SIZE]={0};
- int i;
- for(i=0;i<SIZE;i++){
- printf("Ingrese el %d° valor: ", i+1);
- scanf("%d", &respuesta[i]);
- }
- media(respuesta);
- mediana(respuesta);
- moda(frecuencia, respuesta);
- return 0;
- }
- void media (const int resp[]){
- int j;
- int total=0;
- printf("%s\n%s\n%s\n", "********", " Media", "********");
- for (j=0;j<SIZE;j++){
- total+=resp[j];
- }
- printf ("La media corresponde a : %d\n", total/SIZE);
- }
- void mediana (int resp[]){
- printf("\n%s\n%s\n%s\n%s", "********", " Mediana", "********", "El arreglo de respuestas desordenado es");
- imprimeArreglo(resp);
- ordenamBurbuja(resp);
- printf ("\n\nEl arreglo ordenado es ");
- imprimeArreglo(resp);
- printf ("\nLa mediana es el elemento N°%d del arreglo.\n",SIZE/2);
- printf ("En este caso corresponde a: %d\n", resp[SIZE/2]);
- }
- void moda (int frec[], const int resp[]){
- int rango, j, h, masGrande=0, valorModa=0;
- printf ("\n%s\n%s\n%s\n", "********"," Moda", "********");
- for (rango=1;rango<=9;rango++){
- frec[rango]=0;
- }
- for (j=0;j<SIZE;j++){
- ++frec[resp[j]];
- }
- printf ("%s%11s%19s\n\n", "Respuesta", "Frecuencia","Histograma");
- for(rango=1;rango<=9;rango++){
- printf ("%8d%11d ", rango, frec[rango]);
- if (frec[rango]>masGrande){
- masGrande=frec[rango];
- valorModa=rango;
- }
- for (h=1;h<=frec[rango];h++){
- printf ("*");
- }
- printf ("\n");
- }
- printf ("La moda corresponde a: %d\n", valorModa);
- printf ("Dicho valor se repitió %d veces.\n", masGrande);
- }
- void ordenamBurbuja(int a[]){
- int pasada, j, almacena;
- for (pasada=1;pasada<SIZE;pasada++){
- for (j=0;j<SIZE-1;j++){
- if (a[j]>a[j+1]){
- almacena=a[j];
- a[j]=a[j+1];
- a[j+1]=almacena;
- }
- }
- }
- }
- void imprimeArreglo(const int a[]){
- int j;
- for (j=0;j<SIZE;j++){
- if(j%20==0){ //comienza nueva linea cada 20 valores
- printf ("\n");
- }
- printf (" %d", a[j]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement