codescracker


c

C Program to Count Occurrence of Positive, Zero and Negative Numbers



« Previous Program Next Program »


Count Positive, Zero, and Negative Numbers in C

To count the number of positive number, negative number, and zero from the given set of numbers entered by user in C Programming, just check all the number using for loop that the number is 0, less than zero or greater than 0 to count the occurrence of positive numbers, negative numbers and zero.

C Programming Code to Count Occurrence of Positive, Zero and Negative Numbers

Following C program ask to the user to enter 10 numbers to check for number of positive number, negative number and zero occurrence, then display the result on the screen:

/* C Program - Count Occurrence of Positive, Zero, and Negative Numbers */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int countp=0, countn=0, countz=0, arr[10], i;
	printf("Enter 10 numbers : ");
	for(i=0; i<10; i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=0; i<10; i++)
	{
		if(arr[i]<0)
		{
			countn++;
		}
		else if(arr[i]==0)
		{
			countz++;
		}
		else
		{
			countp++;
		}
	}
	printf("Positive Numbers = %d\n",countp);
	printf("Negative Numbers = %d\n",countn);
	printf("Zero = %d",countz);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program count positive negative zero

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test