Algorithm:
- Start program
- Ask the user to enter an integer to find the factorial
- Read the integer and assign it to a variable
- From the value of the integer up to 1, multiply each digit and update the final value
- The final value at the end of all the multiplication till 1 is the factorial
- Stop the program
Program:
#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
int n;
printf(“Enter a positive integer: “);
scanf(“%d”,&n);
printf(“Factorial of %d = %ld”, n, multiplyNumbers(n));
return 0;
}
long int multiplyNumbers(int n) {
if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
}
Output:
Enter a positive integer: 6
Factorial of 6 = 720