Saturday, August 18, 2018

COUNTING AND SUMMING

  • Problem Description

    Return the count of positives numbers and the sum of negative numbers for the given array.
  • CONDING ARENA
  • #include <stdio.h>
    int main()
    {
      int a,b,i,pos,neg;
      scanf("%d",&a);
      for(i=0;i<a;i++)
      {
        scanf("%d",&b);
        if(b>0)
          pos=pos+1;
        else
          neg=neg+b;
      }
      printf("%d\n",pos);
      printf("%d\n",neg);
      return 0;
    }
  • Test Case 1

    Input (stdin)
    15
    
    1 2 3 4 5 6 7 8 9 10 -11 -12 -13 -14 -15
    
    
    Expected Output
    10
    
    -65
  • Test Case 2

    Input (stdin)
    14
    
    0 2 3 0 5 6 7 8 9 10 -11 -12 -13 -14
    
    
    Expected Output
    8
    
    -50

1 comment: