using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication71
{
class factorial
{
static long Facl;
public static bool Fac(long n, out long answer)
{
long k;
bool ok = true;
if (n <= 0 || n > 20)
{
ok = false;
}
else
{
Facl = 1;
for (k = 2; k <= n; ++k)
{
Facl = Facl * k;
}
answer = Facl;
return ok;
}
}
static void Main(string[] args)
{
long facl;
bool ok;
long number;
Console.WriteLine("enter the number for calculating factorial(1-20):");
number = long.Parse(Console.ReadLine());
ok = factorial.Fac(number, out facl);
if (ok)
Console.WriteLine("factorial(" + number + ")=" + facl);
else
Console.WriteLine("incorrect value");
Console.ReadLine();
}
}
}
No comments:
Post a Comment