Start learning free

LESSON 163 OF 674 · LOOPS & CONDITIONALS

Positive Number In Array: Buggy Code in C#

Practice

Inside the code editor we've tried to write a function that takes an array nums as argument and returns true if there exists at least one positive (greater than zero) number in the array; returns false otherwise.

So when we called the function for new int[]{-1, 2, 3}, we expected our code to print:

Array has positive numbers

but it seems like we made some mistakes: the first number is not positive, so the code returns false right away, which would print:

Array doesn't have positive numbers

In fact, the C# compiler rejects our code with the error not all code paths return a value.


Assignment:

Your task is to fix our function.

STEP 1 OF 1
    Ctrl + Enter to check