Home > Back-end >  C language recursion
C language recursion

Time:09-17

Why do you write on the oj time will overrun, and if the judge in the condition of n to 0, time won't overrun (n<=12)

CodePudding user response:

Should be n=0, this kind of situation

CodePudding user response:

Because 0 factorial is equal to 1, so want to consider the situation of f (0)

CodePudding user response:

Why time will overrun

CodePudding user response:

reference your little chestnut reply: 3/f
why would overrun time

Because if the calculated fact (0), your code doesn't exit, infinite recursion.

CodePudding user response:

Understand, thank you

CodePudding user response:

The recursive algorithm is time-consuming
  • Related