About Lesson
C program that uses a function to find the factorial of a given non-negative integer.
#include <stdio.h>
// Function to calculate the factorial of a number
unsigned long long calculateFactorial(int num) {
if (num == 0 || num == 1) {
return 1;
} else {
return num * calculateFactorial(num – 1);
}
}int main() {
int number;// Taking input for the number
printf(“Enter a non-negative integer: “);
scanf(“%d”, &number);// Calling the function to calculate the factorial and printing the result
unsigned long long factorial = calculateFactorial(number);
printf(“Factorial of %d is: %llun”, number, factorial);return 0;
}