Factorial using Recursion C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Factorial
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(factorial(4));
Console.ReadLine();
}

static int factorial(int n)
{
if (n > 1)
{
return factorial(n - 1) * n;
}
else
{
return 1;
}
}
}
}

Comments

  1. It was really helpful...Thanks a lot!

    ReplyDelete
  2. It only works up to 12; 13 gave an incorrect value. I had to change the value type to long to get the correct value.

    ReplyDelete

Post a Comment

Popular posts from this blog

Network Security: LAN manager authentication level

Cisco AnyConnect Secure Mobility Client - VPN service not available. The VPN agent service is not responding