Canna

Thursday, 27 September 2018

Counting and Summing

  • Problem Description

    Return the count of positives numbers and the sum of negative numbers for the given array.
  • 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
  • Program
  • #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;
    }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.