factorials - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# factorials

Posts: 103Member
hello i am trying to write a program to calculate the factorials of all intergers up to 20

and display them like this:

1=1
3*1=2
3*2*1=6
etc

the hardest part is the formula to do this,

any help would be very appreciated.

many thanks,
ed.

## Comments

• Posts: 6,349Member
: hello i am trying to write a program to calculate the factorials of all intergers up to 20
:
: and display them like this:
:
: 1=1
: 3*1=2
: 3*2*1=6
: etc
:
: the hardest part is the formula to do this,
:
: any help would be very appreciated.
:
: many thanks,
: ed.
:
Here's the calculation and part of the output generation:
[code]
int Fact(int value, String output) {

output = output + '*' + String.valueOf(value);

if (value > 1)
return value*Fact(value-1, output);
else
return 1;
}
[/code]
Parameters:
- value = number you want the factorial of
- output = the string representation of the factorial calculation
Returns:
the factorial of value
Sign In or Register to comment.