logo CodeStepByStep logo

MirrorSequence

Language/Type: C# recursion
Related Links:

Write a recursive method named MirrorSequence that accepts an integer parameter n and prints a sequence of n numbers as in the table below. For odd numbers the sequence has a single 1 in the middle, while for even values it has two 1s in the middle. Throw an ArgumentException if passed a value less than 1.

Call Output
MirrorSequence(1); 1
MirrorSequence(2); 1 1
MirrorSequence(3); 2 1 2
MirrorSequence(4); 2 1 1 2
MirrorSequence(5); 3 2 1 2 3
MirrorSequence(6); 3 2 1 1 2 3
MirrorSequence(7); 4 3 2 1 2 3 4
MirrorSequence(8); 4 3 2 1 1 2 3 4
MirrorSequence(9); 5 4 3 2 1 2 3 4 5
MirrorSequence(10); 5 4 3 2 1 1 2 3 4 5
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.