Skip to content

Instantly share code, notes, and snippets.

@jmramirezpro
Created April 14, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmramirezpro/328e5582b2c9655dcc9c284c623f5e53 to your computer and use it in GitHub Desktop.
Save jmramirezpro/328e5582b2c9655dcc9c284c623f5e53 to your computer and use it in GitHub Desktop.
/*
* MinMax.c
* Ejercicios del Podcast Codigo Fuente - Programa 29
* Escribir un programa que calcule el mínimo, el máximo y la media de una
* lista de números enteros positivos introducidos por el usuario.
* La lista finalizará cuando se introduzca un número negativo.
* Creado el 14 de abr. de 2016
* Author: jmramirez
*/
#include <stdio.h>
int main(int argc, char *argv[])
{
int n;
int minimo, maximo, media;
int ret, ntotal, suma;
printf("Introduce un número: " );
ret = scanf("%d", &n);
if ((ret == 0) || n < 0){
return (0);
}
minimo = n;
maximo = n;
suma = n;
ntotal = 1; /* Cantidad de numeros leidos */
media = 0;
printf("Introduce un número: " );
ret = scanf("%d", &n);
while ((ret == 1) && (n >= 0)) {
if (n < minimo)
minimo = n;
if (n > maximo)
maximo = n;
suma = suma + n;
ntotal++;
printf("Introduce un número: " );
ret = scanf("%d", &n);
}
media = suma / ntotal;
printf("\n");
printf("minimo = %d\n",minimo);
printf("maximo = %d\n",maximo);
printf("media = %d\n",media);
printf("\n");
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment