C#.net Code to Find Factorial of a Given Number
It is easy to find Factorial of given number in C#.net only 2 texboxes is needed for inputting and outputting
firstly create a new project in visual studio with C# code the form must have 2 textboxes,2 labels and a button. select the firt textbox(input textbox) set the name as txtNumber,select the second textbox(output textbox) set the name as txtFactorial ,select the button and set the name as btnFactorial ,select the first label and set the text as Enter the Number,select the second label and set the text as Factorial after this we finishes the designing part my form design is like this
this is my forms design the factorial is printed in the 2nd textbox the first textbox will be the inputting texbox
After creating the form double click the button and write the following codes
private void btnFactorial_Click(object sender, EventArgs e)
{
int count=1,factorial=1,number=1,factorialNumber;
factorialNumber=Convert.ToInt32(txtNumber.Text);
while (count<= factorialNumber )
{
factorial = factorial * number;
count ++;
number++;
}
txtFactorial.Text = factorial.ToString();

No comments:
Post a Comment