开发者

C++ I have two questions [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Please h开发者_如何学Pythonelp me with my homework:

  • There is an array a [20] of float numbers, Enter number in the array. Find the sum of negative number.
  • Enter 10 integer numbers in the array a [10]. Find the sum of positive numbers.


General psuedo-code to get you in the right direction for finding the sum of positive numbers in the array:

float result = 0;
for(int i = 0; i < array_length; i++)
{
  if(array[i] > 0)
    result = result + array[i];
}

For the sum of negative numbers, just switch the if-statement. Of course, this isn't exactly C++ code, but I think you can make it work from here pretty easily enough. :)


You access a value with the [] operator, so for instance, accessing the first value from the array a, you write a[0].

After that it is a matter of using for to iterate over the numbers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜