write code for Factorial?
Answers were Sorted based on User's Feedback
Answer / rajender
private void btnCalculae_Click(object sender,
System.EventArgs e)
{
long number = Convert.ToInt64 (txtNumber.Text);
long factorial = 1;
lblFactorial.Text = factorial.ToString
("n20");
// calculate factorial
while ( number > 0 && number <= 20)
{
factorial *= number;
number++;
} // end while loop
txtNumber.Text = "";
txtNumber.Focus();
}
private void btnExit_Click(object sender,
System.EventArgs e)
{
this.Close();
}
}
}
Is This Answer Correct ? | 10 Yes | 1 No |
Answer / dharmendra nonia
using System;
class Factorial
{
public static void accept()
{
double a;
Console.WriteLine("Enter ur Number:");
a=Double.Parse(Console.ReadLine());
double res=fac(a);
Console.WriteLine(res);
}
public static double fac(double d)
{
if (d == 1)
return 1;
else
return d * fac(d - 1);
}
public static void Main()
{
accept();
Console.Read();
}
}
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / diana cheriyan
Using System;
Namespace FactNmspce
{
Class FactCls
{
Public Static Void Main(String[]args)
{
int i,n,fact=1;
Console.WriteLine("Enter Number");
n=int.Parse(Console.ReadLine());
for(i=1;i<=n;i++)
{
fact=fact*i;
}
Console.WriteLine("Factorial is {0}",fact);
}
}
}
Is This Answer Correct ? | 12 Yes | 5 No |
Answer / shanker
int numberfactorial(int number)
{
if (number == 1) {
return number;
}
else {
return number * numberfactorial(number - 1);
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / dilip tekedil
public long Factorial(short num)
{
if (num == 1) return (long)1;
return num * Factorial(--num);
}
Is This Answer Correct ? | 4 Yes | 5 No |
Answer / sathish
private void btnCalculae_Click(object sender,
System.EventArgs e)
{
string str =txt1.text;
int fact=1;
foreach char c in str
{
fact=convert.toint32(c)*fact;
}
txt2.text=fact;
}
Is This Answer Correct ? | 4 Yes | 6 No |
Is it possible to execute multiple catch block for a single try statement?
What is the difference between selection and projection?
What is the function of .IsDescendent()?
Can I use exceptions in c#?
How does the lifecycle of Windows services differ from Standard EXE?
What is ienumerable t in c#?
int a = '3' + '4'; char n = (char)a; What will be answer of n?
What is different between Static Constructor and Private Constructor?
Explain the process of inheriting a class into another class?
You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?
What is meaning of type safety in c#?
What is typeof undefined?