Translate

Factorial n Using C++

               Factorial N Using C++ 

 Code : #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 number : 5
Factorial of 5 = 120


No comments:

Post a Comment

If you have any doubt, please let me know.