Complete following function which receives an array of integers and the length of the array, and then returns the sum of all the positive numbers in the array. For example, if an array that is passed to this function contains following numbers: -1, 2, 0, 3, 4, -3, 0, 2, 0, and then the return value of the function should be 11. Will this function be working correctly? Yes or No?
int sumPositive(int a[],int length)
{
int s=0;
for(int i=0;i<length;i++){
if(a[i]>0)
s+=a[i];
}
return s;
}
Multiple choice
Yes or no
Yes, it works. Below is the screenshot of the execution of the program:
Get Answers For Free
Most questions answered within 1 hours.