This question has already been answered:

Tell me how to calculate and display factorial, through return?

Reported as a duplicate by participants in Visman , Abyx , Harry , edem , Community Spirit Jul 29 '17 at 4:41 pm .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    ru.stackoverflow.com/questions/2479/... look at the algorithm there and try to implement it if it fails - correct the question - Lex Hobbit
  • It's easy to calculate ... but how to make a dog meow? ... - Harry

2 answers 2

Just count -

unsigned int factorial(unsigned int n) { unsigned int resulr = 1; if (n > 1) while(n > 1) res *= n--; return res; } 

But the return not intended to be displayed on the screen; use, for example, the printf function.

    In general, it is necessary through if the value of nb <1 fits in. Where nb is a factorial, and then everything is completed and else nb> 1 and then n ++. At the end of the output return nb;

    • 8-0 And how does return still perform output to the screen? - Harry
    • one
      This is not an answer. Use the edit button and edit the question. - 0xdb
    • Yes, no problem through the withdraw output. Or so return printf(...); or return factorial(n); and then echo $? in the console echo $? . - KoVadim