In mathematics, the notation n! represents the factorial of the nonnegative inte
ID: 3548090 • Letter: I
Question
In mathematics, the notation n! represents the factorial of the nonnegative integer n. The factorial of n is the product of all the nonnegative integers from 1 through n.
For example,
7! = 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5,040
and
4! = 1 x 2 x 3 x 4 = 23
Create an application that lets the user enter a nonnegative integer and then uses a loop to calculate the factorial of that number. Display the factorial in a label or a message box.
- Have title in the form.
- Have Try.. Catch block in your program.
- Have Accept and Cancel Buttons.
- Assign Keyboard Access keys to Buttons.
Explanation / Answer
int Factorial(int input) { int answer = 0; if (input > 0) { count = 1; while (count <= input) { if (count == 1) { answer= 1; count++; } else { answer = count * answer; count++; } } } else { MessageBox.Show("Please enter only a positive integer."); } return answer; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.