How to count the positive numbers and the negative numbers in C

1 Answer

0 votes
#include <stdio.h>
 
int main(void)
{
    int n, neg = 0, pos = 0;
 
    printf("Enter a numbers: ");
    scanf("%d", &n); // first input
 
    while (n != 0)
    {
        if (n > 0)
            pos = pos + 1; // count the positive numbers
        if (n < 0)
            neg = neg + 1; // count the negative numbers
        printf("Enter other number: ");
        scanf("%d", &n); // next input 2, input 3, input 4, ... until user enter: 0
    }
    printf("There are %d positive numbers and %d negative numbers", pos, neg);
 
    return 0;
}


answered Jul 25, 2014 by avibootz
...