Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int n, i, a;
- int cantPos = 0, cantNeg = 0;
- int sumaPos = 0, sumaNeg = 0;
- float promPos = 0, promNeg = 0;
- int cantCeros = 0;
- scanf("%d", &n);
- if(n < 0 || n > 12)
- {
- printf("Valor excedido\n");
- return 0;
- }
- for(i=0; i<n; i++)
- {
- scanf("%d", &a);
- if(a < 0)
- {
- cantNeg++;
- sumaNeg += a;
- }
- else if(a > 0)
- {
- cantPos++;
- sumaPos += a;
- }
- else
- {
- cantCeros++;
- }
- }
- if(cantPos > 0)
- promPos = (float)sumaPos/cantPos;
- if(cantNeg > 0)
- promNeg = (float)sumaNeg/cantNeg;
- printf("Promedio de los positivos: %f\n", promPos);
- printf("Promedio de los negativos: %f\n", promNeg);
- printf("Cantidad de ceros: %d\n", cantCeros);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement