Howto compute the factorial of x

前端 未结 7 1385
一生所求
一生所求 2020-12-20 00:05

how to get the value of an integer x, indicated by x!, it is the product of the numbers 1 to x.

Example: 5! 1x2x3x4x5 = 120.

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 00:19

    You can simply do:

    for(b = 1; b <= a; b++) {
      d *= b;
    }
    // d now has a!
    

提交回复
热议问题