Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


Count positive negative numbers using for loop in c program


Program to count the occurrence of positive numbers, negative numbers from the given set of number using for loop.

Example : pgm.c

#include<stdio.h>
int main()
{
    int i,n,a,pos=0,neg=0;
    printf("\nEnter the Limit : ");
    scanf("%d",&n);
    for(i=0;i<n;i++){
        printf("\nEnter the %d Number : ",i+1);
        scanf("%d",&a);
        if(a>0){
            pos++;
        }else{
            neg++;
        }
    }
    printf("\nNo of Positive : %d",pos);
    printf("\nNo of Negative : %d",neg);
    return 0;
}

Output:

Enter the limit:
5
Enter the 1 Number : 2
Enter the 2 Number : -8
Enter the 3 Number : 10
Enter the 4 Number :-99
Enter the 5 Number : 7
No of Positive : 3
No of Negative : 2