# Using recursion to print alternating squares?

Bear Kim
Greenhorn
Posts: 9
Hi, I'm trying to use recursion (no loops) to print out descending odd, then ascending even squares less than a certain number.
For examples, squares(5) would print out: 25, 9, 1, 4, 16.
I'm not sure how I would alternate between even/odd, and would really appreciate some help with that.

Right now, I have it so that all squares are printed in descending order. All input is greatly appreciated!

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
You are almost done.
One Suggestion: why do you throw Exception from base condition, I do suggest you to just return.

Hint : even number * even number => even number ; odd number * odd number => odd number.
So, when you encounter even number dont print it instead put into a *X* datastructure. and print it later in base condition before return.

Darryl Burke
Bartender
Posts: 5132
11
• 1

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Good Kim, you wasted my time!

Bear Kim
Greenhorn
Posts: 9
Sorry, I'm confused, why is cross-posting bad? Thanks for the help anyways though, other site wasn't much help.

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Bear Kim wrote:why is cross-posting bad?

refer Darryl's Post.