Beruflich Dokumente
Kultur Dokumente
Factorial+of+a+number
Factorial of a number [Answered]
13 replies
Last post May 08, 2012 01:03 PM by AccuWebHosting.Com
Factorial of a number
May 08, 2012 02:03 AM | .net_junkie
int Number=1;
Number=Convert.ToInt32(TextBox1.Text);
if(Number==0)
Label1.Text="enter a number greater than 0";
else
//int functionReturnValue = 0;
//functionReturnValue = 1;
for (int i = 0; i >Number-1; i--)
{
Number=Number*i;
}
Label1.Text=Convert.ToString(Number);
}
}
int Number=1;
Number=Convert.ToInt32(TextBox1.Text);
if(Number==0)
Label1.Text="enter a number greater than 0";
else
1 of 7 20-03-2019, 23:14
Factorial of a number | The ASP.NET Forums https://forums.asp.net/t/1801249.aspx?Factorial+of+a+number
Hi,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Factorial
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" Give me the number you want the factorial: \n ");
long a = Convert.ToInt64(Console.ReadLine());
Console.WriteLine(" The factorial of given number is: " + Factorial(a));
Console.ReadKey();
}
2 of 7 20-03-2019, 23:14
Factorial of a number | The ASP.NET Forums https://forums.asp.net/t/1801249.aspx?Factorial+of+a+number
long Number = 1;
Number = Convert.ToInt64(TextBox1.Text);
if (Number == 0)
Label1.Text = "enter a number greater than 0";
else
{
Number = Factorial(Number);
}
Label1.Text = Convert.ToString(Number);
and i want the code with recursion also can anyone provide me the code??
Hi,
3 of 7 20-03-2019, 23:14
Factorial of a number | The ASP.NET Forums https://forums.asp.net/t/1801249.aspx?Factorial+of+a+number
tusharrs
Hi,
For eg::
the input no : is 3
and now for Factorial(2) the same process will occur until ot enters the if block the same recursive process will
continue and u ll get the required output.
4 of 7 20-03-2019, 23:14
Factorial of a number | The ASP.NET Forums https://forums.asp.net/t/1801249.aspx?Factorial+of+a+number
number * factorial(number-1)
finally 6 * factorial(5) i.e. 120 * factorial(4) i.e. 24 * factorial(3) i.e. 6 * factorial(2) i.e. 2 * factorail(1) i.e. 1
So factorial is a method and we are using this code in other part and we are passing aprameters isnt it?
factorial is a function which takes a parameter of datatype long and returns the factorial of datatype long
Hi,
5 of 7 20-03-2019, 23:14
Factorial of a number | The ASP.NET Forums https://forums.asp.net/t/1801249.aspx?Factorial+of+a+number
your loop condition is wrong it should be i<number, go on and store result in some third variable
Hi!
if (n <= 1)
return 1;
int result = 1;
result = result * i;
return result;
To find the factorial of given number you can use Recursive Function also :
if (n <= 1)
return 1;
6 of 7 20-03-2019, 23:14
Factorial of a number | The ASP.NET Forums https://forums.asp.net/t/1801249.aspx?Factorial+of+a+number
Regards.
This site is managed for Microsoft by Neudesic, LLC. | © 2019 Microsoft. All rights reserved.
7 of 7 20-03-2019, 23:14