Factorial is a mathematical formulation. It is represented by "!" (exclamation mark). It is return the integer value.The product of all the positive integers from 1 to a given positive integer. For example(5!=1*2*3*4*5).
#include<stdio.h> //Header Files #include<conio.h> #include<getch.h> long fact(int); //Function Decleration void main() //Execution Start From here { long f; int n; clrscr(); printf("Enter the Number"); scanf("%d",&n); f=fact(n); printf("\nFactorial is = %d",f); getch(); } long fact(int n) //function Definition { if(n==1) { return 1; } else { return n*fact(n-1); } }
Factorial Execution in Javascript
Example Program:- (Editor)
Editor is Loading...
Important Part
Execution:-
1st Calling ---> 5*fact(4) <---| 5*24
2nd Calling ---> 4*fact(3) <---| 4*6
3rd Calling ---> 3*fact(2) <---| 3*2
4th Calling ---> 2*fact(1) ----| 2*1 Calculation start from here(bottom to top)!
1st Calling ---> 5*fact(4) <---| 5*24
2nd Calling ---> 4*fact(3) <---| 4*6
3rd Calling ---> 3*fact(2) <---| 3*2
4th Calling ---> 2*fact(1) ----| 2*1 Calculation start from here(bottom to top)!
Advertisement
0 comments:
Post a Comment