when the name of function is factorial, how is the...

Discussion in 'Web App and Programming' started by _18940, Dec 26, 2017.

  1. _18940

    _18940 Member

    Joined:
    Dec 25, 2017
    Messages:
    4
    Likes Received:
    0
    when the name of function is factorial, how is the function calling itself in else condition with fact(n-1). Shouldn't it be fact = n * factorial(n-1)??
     
    #1
  2. Rakesh Deshpande

    Rakesh Deshpande Moderator
    Simplilearn Support

    Joined:
    May 3, 2016
    Messages:
    703
    Likes Received:
    47
    Hello,

    It depends on the same where the base program of factorial is fact(//arguments) or factorial(//arguments), depending on the same function name, you would proceed using the same name. Hope this helps!
     
    #2
  3. _18940

    _18940 Member

    Joined:
    Dec 25, 2017
    Messages:
    4
    Likes Received:
    0
    yes, so in the example shared, the function name is factorial hence it should be fact = n * factorial(n-1)
     
    #3
  4. Priyanka_Mehta

    Priyanka_Mehta Well-Known Member
    Simplilearn Support

    Joined:
    May 25, 2017
    Messages:
    488
    Likes Received:
    34
    Hi Aditya,

    It totally depends on the example you are referring. So if in the example function name is factorial then your statement is absolutely coreect:
    fact = n * factorial(n-1)

    If still you are stuck with the concept, I would request you to share the example here, which you are referring. So that we can help you more accurately.
     
    #4

Share This Page