-4

My professor give me this code i need to know why is the output is 720 and what is the used of FACT word in this code

static int Fact(int num)
{
    if (num == 1)

        return 1;

    else return num * Fact(num - 1);

}

static void Main(string[] args)
{
    Console.WriteLine(Fact(6));
} //output is 720
  • 3
    This is clearly a school question to calculate a factorial using recursion. – IronAces Aug 02 '18 at 15:42
  • You should get started by reading a c# tutorial. Look here: [Methods (C# programming)](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods) – Camilo Terevinto Aug 02 '18 at 15:43
  • 1
    Aside: The missing braces on the return does not make for a friendly-to-learn example. – IronAces Aug 02 '18 at 15:44
  • 1
    only if you listen to your professor in the class. – M.kazem Akhgary Aug 02 '18 at 15:48
  • `Fact` is nothing magic or special. It is just the name your professor gave to a function. However I would recommend your professor to read _Clean Code_ from Robert C. Martin, or at least [this excerpt](https://stackoverflow.com/a/853187). Then he should consider naming it `factorial`. That would avoid that his students need to ask such questions. – Adrian W Aug 02 '18 at 16:28

1 Answers1

0

Fact is short for factorial, the product of all the natural integers up to a given integer. The code snippet here implements a factorial calculation of the argument num in a recursive way.

Mureinik
  • 297,002
  • 52
  • 306
  • 350