Program to calculate Factorial.
Call this function from your main
Like :-
1: void fact() {
2: int n ,i,f = 1;
3: printf("Enter number you want to calculate factorial\n");
4: scanf("%d",&n);
5: for(i = 1 ; i <= n ; i++) {
6: f = f*i;
7: }
8: printf("\n Factorial of %d is = %d\n",n,f);
9: Output :- Enter number you want to calculate factorial 5
10: Factorial of 5 is = 120
Call this function from your main
Like :-
1: int main() {
2: fact();
3: }
No comments:
Post a Comment