adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Write a program in C to count the numbers of positive, negative and zero in an array.

Write a program in C to count the numbers of positive, negative and zero in an array.

#include<stdio.h>
#include<conio.h>
  void main()
    {
       int a[100],i,n,pos=0,neg=0,zero=0;
       clrscr();
        printf("Enter a number you want to inset in array:-");
        scanf("%d",&n);
        printf("Enter %d numbers:-",n);
        for(i=0;i<n;i++)
        {
       scanf("%d",&a[i]);
        }
         for(i=0;i<n;i++)
         {
       if(a[i]>0)
          pos++;
       else if(a[i]<0)
          neg++;
       else 
          zero++;
      }
      printf("\nPositive nos.=%d",pos);
      printf("\nNegative nos.=%d",neg);
      printf("\nZero nos.=%d",zero);
      getch();
     }

Output:-

Post a Comment

0 Comments