64 720
Assignments Done
99,4%
Successfully Done
In September 2018

Answer to Question #12223 in C# for Han Mia

Question #12223
Write a program to determine the largest value of n such that your computer can compute n! without integer overflow. n! is the product of all positive numbers that are less than or equal to n. For example, 3! = 1 x 2 x 3 = 6. By convention, 0 is set equal to 1.
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Factorial
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number (< 0 to stop): ");
int num = Int32.Parse(Console.ReadLine());
while (num > 0)
{
Console.WriteLine(num + "! = " + factorial(num));
Console.Write("Enter a number ( <0 to stop): ");
num = Int32.Parse(Console.ReadLine());
}
Console.ReadLine();
}
public static double factorial(long n)
{
if (n < 1)
return 0;
double product = 1;
for (int i = 1; i <= n; i++)
product *= i;
return product;
}
}
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions