Hey all again,
At Uni we have just started looking at recursive calls and I'm a little baffled by it all.
What I'm trying to do is figure out the triangular number series just using recursion. I know how to do it:
But I cannot seem to get the program to print out each number in the list it just seems to always print out the last number usually 1. So could someone be kind-full enough to show how I would get the numbers to print out in order please.
I'm doing this in C++ but provide code in any language I should be able to decipher it
.
Thanks again,
Stephen
At Uni we have just started looking at recursive calls and I'm a little baffled by it all.
What I'm trying to do is figure out the triangular number series just using recursion. I know how to do it:
Code:
int triangular(int x) {
if (x == 0) return 0;
if (x == 1) return 1;
return x + triangular(x-1);
}
But I cannot seem to get the program to print out each number in the list it just seems to always print out the last number usually 1. So could someone be kind-full enough to show how I would get the numbers to print out in order please.
I'm doing this in C++ but provide code in any language I should be able to decipher it
Thanks again,
Stephen