You must create a flowchart, and its corresponding Python program, to solve the following problem:
1. Using a repetition structure, evaluate the factorial of a positive whole number n:
n! = n · (n - 1) · (n - 2) · ... · 1, where n >=1
Your program must take into account the cases in which the user
enters an incorrect number
and provide an error message for such cases.
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
// shows error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't
exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.