Problem Description
Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.
If the input array is empty or null, return an empty array:CODING ARENA
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int i,p=0,n1=0,a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>=0)
p++;
else
n1=n1+a[i];
}
if(p!=0||n!=0)
printf("Count of positive numbers=%d\nSum of negative numbers=%d\n",p,n1);
else
printf("0");
return 0;
}
Test Case 1
Input (stdin)15 1 2 3 4 5 6 7 8 9 10 -11 -12 -13 -14 -15
Expected OutputCount of positive numbers=10 Sum of negative numbers=-65
Test Case 2
Input (stdin)14 0 2 3 0 5 6 7 8 9 10 -11 -12 -13 -14
Expected OutputCount of positive numbers=10 Sum of negative numbers=-50
No comments:
Post a Comment