Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

factorials

rootroot 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

  • zibadianzibadian 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.