Dynamically Add Rows to an Array

Started by
10 comments, last by PsyberMind 13 years, 3 months ago
Quote:Original post by PsyberMind
WooHoo! I did it on the first try (I think)
Congratulations [smile]

A few constructive comments on your process function...

The name 'process' is unhelpfully generic, always give things descriptive names, in this case something like 'factorial' would be sufficient.

Your function implementation is reasonably long-winded for what it does. First you have separated the declaration of temp from its initialisation - this wasn't necessary as you could have both initialised and declared temp in a single statement, which is the preferred practice when it's possible to do so:

int temp = number * factorial(number - 1);

Secondly, you don't actually need an explicit variable at all! You can simply return the value directly rather than assigning it to temp first:

int factorial(int number){	if (number <= 1) return 1;	return number * factorial(number - 1);}


Advertisement
Got it, and that does make things a little cleaner :) Thank you!

On to the next exercise!

This topic is closed to new replies.

Advertisement