/* This is the eleventh lab of Lab EE107
The purpose of this lab for a recursive function to calculate the
factorial of a positive integer.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 9th, 2024.
*/
#include <stdio.h>
// Recursive function to calculate the factorial of a positive integer
unsigned long long factorial(unsigned int n) {
// Base case: factorial of 0 is 1
if (n == 0) {
return 1;
}
// Recursive case: n! = n * (n-1)!
else {
return n * factorial(n - 1);
}
}
int main() {
// Test the factorial function
unsigned int n = 5;
printf("Factorial of %u is %llu\n", n, factorial(n));
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: