Factorial using Addition

后端 未结 4 916
眼角桃花
眼角桃花 2021-01-28 14:19

I am attempting to create a C code that finds the factorial of a integer so that I may convert my code to assembly language. My code seems to \'multiply\' the second integer twi

4条回答
  •  旧巷少年郎
    2021-01-28 14:32

    Here's the machine state, from which you should be able to see why your algorithm isn't right:

    PS Another, perhaps better, way to think about this is that your mathematics is wrong. You're doing three multiplications (repetitions of the inner loop--multiplying by an integer using repeated addition). But you also do three additions of the products. Those sums tell you that you're not computing a factorial.

提交回复
热议问题