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 a[50],n,i,t=0,c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<0)
{
t=t+a[i];
}
else
{
c++;
}
}
printf("Count of positive numbers=%d\n",c);
printf("Sum of negative numbers=%d",t);
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