Friday, August 17, 2018

PRINT 6-COUNT OF POSITIVE AND NEGATIVE

  • Write a C program to find allow the user to enter n number and finds the number of positive numbers entered and number of negative numbers entered entered using a while loop

    Input format:

    Input consists of n+1 integers. The first integer corresponds to n and the next n integers correspond to the numbers to be added. Consider 0 to be a positive number
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int a,b,i,x=0,y=0;
      scanf("%d",&a);
      for(i=0;i<a;i++)
      {
        scanf("%d",&b);
        if(b<0)
        {
          x=x+1;
        }
        else
        {
          y=y+1;
        }
      }
      printf("positive numbers count=%d",y);
      printf("\nnegative number count=%d",x);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    4
    
    5 -2 -1 6
    
    
    Expected Output
    positive numbers count=2
    
    negative number count=2
  • Test Case 2

    Input (stdin)
    5
    
    1 3 -1 -2 -3
    
    
    Expected Output
    positive numbers count=2
    
    negative number count=3

No comments:

Post a Comment