logo CodeStepByStep logo

Zigzag

Language/Type: C# recursion
Related Links:

Write a recursive method Zigzag that accepts an integer parameter n and that prints out n characters as follows. The middle character of the output should always be an asterisk ("*"). If you are asked to write out an even number of characters, then there will be two asterisks in the middle ("**"). Before the asterisk(s) you should write out less-than characters ("<"). After the asterisk(s) you should write out greater-than characters (">"). For example, the following calls produce the following output:

Call Output
Zigzag(1); *
Zigzag(2); **
Zigzag(3); <*>
Zigzag(4); <**>
Zigzag(5); <<*>>
Zigzag(6); <<**>>
Zigzag(7); <<<*>>>
Zigzag(8); <<<**>>>

Your method should throw an ArgumentException if passed a value less than 1. Note that the output does not advance to the next line.

Method: Write a C# method as described, not a complete program or class.

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.