The factorial of a nonnegative integer n is written n! (pounced \"a factorial\")
ID: 3121979 • Letter: T
Question
The factorial of a nonnegative integer n is written n! (pounced "a factorial") and is defined as follows: n! = n middot (n-1) middot (n-2) middot ...... middot 1 (for value of n greater than or equal to 1) and n! = 1 (for n = 0) For example 5! = 5 middot 4 middot 3 middot 2 middot 1 which is 120 Write a program that asks the user to enter a nonnegative integer, then computes and outputs its factorial. However, if the user enters a negative the program will keep asking for a positive integer, number until it receives one.Explanation / Answer
#include int main() { int n=-1, i; unsigned long long factorial = 1; // keep asking if the user enters a negative integer while (n < 0) { printf("Enter an integer: "); scanf("%d",&n); } for(i=1; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.