write code for Factorial?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a byte in c#?

553


Why is main static in c#?

514


What is the property of class?

575


Why do we parse in c#?

464


What is the difference between structure and class in c#?

467






Explain the difference between passing parameters by value and passing parameters by reference with an example?

497


How to reverse each word in a string using c#?

556


Can we override main method in c#?

474


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?

609


What is difference between int and int in c#?

449


How many constructor can a class have?

467


What is the use of regex in c#?

494


What is tochararray in c#?

446


Which function is the entry point for a DLL in MS Windows 3.1?

677


What is lazy loading and eager loading in c#?

482