Answer to Question #295222 in C# for ITSyndicate

Question #295222

Create a program that will implement a method Factorial and return a double

number based on any supplied argument.


1
Expert's answer
2022-02-08T07:54:04-0500

public class HelloWorld

{

  static double Factorial(int n)

  {

    int fact;


    if(n == 0)

    {

     fact = 1;

    }

    else

    {

      fact = 1;

      for(int i = 1; i < n; i++)

      {

        fact += fact * i; 

      }

    }

     

    return fact;

  }

   

  static double FactorialDouble(double n)

  {

    int tmp = (int)n;

    if (((double) tmp) == n)

      n = Factorial(tmp);

    else

      n = Math.Exp(Math.Log(Factorial(tmp)) + (n - tmp) * Math.Log(tmp+1));


    return n;

  }

   

  public static void Main(string[] args)

  {

    Console.Write("Enter number: ");

    double number = double.Parse(Console.ReadLine());

    Console.WriteLine ($"Factorial == {FactorialDouble(number)}!");

  }

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS