WAP to count and print the number of negative and positive numbers in a given set of numbers. Test your program with a suitable set of numbers. Use scanf() to read the numbers. Reading should be terminated when the value 0 is encountered

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 2.6, page 51
#include <stdio.h>
#include <conio.h>
int main(void)
{
int n=0, positive=0, negative=0;

printf("\nPress 0 to complete the data entry\n\n");
do
    {printf("Enter number : ");
    scanf("%d",&n);
    //process it
    if (n>0)
        {positive++;}
    if (n<0)
        {negative++;}
    }
while (n != 0);
//output
printf("\n\n===OUTPUT===\n");
printf("From the input numbers,\n%d are postive, and\n%d are negative",positive, negative);
getch();
return 0;
}

Comments