Thursday, June 6, 2019

Write a C Program to Count Positive, Negative and Zero Numbers

Write a C Program to Count Positive, Negative and Zero Numbers

Program:

#include<stdio.h>
#include<conio.h>
int main()
{

    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();
}
-----------------------------------------------------------------
Output:

Enter 10 numbers : 2
3
-8
0
8
-4
0
0
0
1
Positive Numbers = 4
Negative Numbers = 2
Zero = 4

0 Comments:

Post a Comment