logo CodeStepByStep logo

print_stars

Language/Type: PHP recursion

Write a recursive function named print_stars that accepts an integer parameter $n and prints $n occurrences of the "*" character to the console.

For example, the call of print_stars(5);should print *****. If passed a negative value, your function should throw an Exception with the message, "Error: argument must be non-negative."

Constraints:

  • Do not use any loops; you must use recursion.
Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.