Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int n, i, a;
  7.     int cantPos = 0, cantNeg = 0;
  8.     int sumaPos = 0, sumaNeg = 0;
  9.     float promPos = 0, promNeg = 0;
  10.     int cantCeros = 0;
  11.    
  12.     scanf("%d", &n);
  13.  
  14.     if(n < 0 || n > 12)
  15.     {
  16.         printf("Valor excedido\n");
  17.         return 0;
  18.     }
  19.  
  20.     for(i=0; i<n; i++)
  21.     {
  22.         scanf("%d", &a);
  23.         if(a < 0)
  24.         {
  25.             cantNeg++;
  26.             sumaNeg += a;
  27.         }
  28.         else if(a > 0)
  29.         {
  30.             cantPos++;
  31.             sumaPos += a;
  32.         }
  33.         else
  34.         {
  35.             cantCeros++;
  36.         }
  37.     }
  38.  
  39.  
  40.     if(cantPos > 0)
  41.         promPos = (float)sumaPos/cantPos;
  42.  
  43.     if(cantNeg > 0)
  44.         promNeg = (float)sumaNeg/cantNeg;
  45.  
  46.     printf("Promedio de los positivos: %f\n", promPos);
  47.     printf("Promedio de los negativos: %f\n", promNeg);
  48.     printf("Cantidad de ceros: %d\n", cantCeros);
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement