marcoshuck

Repaso de programación en C

Aug 28th, 2013
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. /*******************************************************************************
  2.             Condicionales, switchs, bucles, centinelas y banderas
  3.                                     by
  4.                             Marcos Andrés Huck
  5.                               2013 - UTN-FRP
  6.                             www.marcoshuck.com
  7. *******************************************************************************/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #define MAX_COMP 50
  12. #define MIN_COMP 100
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16.     float num = 0, /* Número ingresado */
  17.     suma = 0, /* Suma de los números ingresados */
  18.     promedio = 0; /* Promedio de los números ingresados */
  19.     int cont_in = 0, /* Contador de los números */
  20.     cont_rango = 0, /* Contador de los números dentro del rango */
  21.     flag = 0;/* Bandera para salida del búcle */
  22.     do
  23.     {
  24.         printf("Ingrese el valor [%d]: ", cont_in+1);
  25.         scanf("%f", &num);
  26.         if(num != -1)
  27.         {
  28.             suma += num;
  29.             cont_in++;
  30.             if((num > MIN_COMP) && (num < MAX_COMP))
  31.             {
  32.                 cont_rango++;
  33.             }
  34.         }
  35.         else
  36.         {
  37.             flag = 1;
  38.         }
  39.     }
  40.     while(flag == 0);
  41.     promedio = suma/cont_in;
  42.     printf("Numeros ingresados: %d\nSuma total: %.3f\nPromedio: %.3f\nCantidad de numeros comprendidos entre 50 y 100: %d\n", cont_in, suma, promedio, cont_rango);
  43.     system("PAUSE");   
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment