**Q.**Write a function fact to calculate the factorial value of any number.

**Ans.**

/*c program for make function fact to calculate factorial value of any number*/

**#include**<

**stdio.h**>

int fact(int );

int main()

{

int num,f;

printf("Enter any number : ");

scanf("%d",

**&**num);

f = fact(num);

printf("Factorial value of %d is %d",num,f);

**return 0**;

}

int fact(int n)

{

int z=1;

for(; n>=1; n--)

z = z * n;

**return**(z);

}

The output of above program would be:

Screenshot for find factorial value using Figure:user define function C program |

why to return(z);

ReplyDeletez store the value of factorial, so according to program we want the display the result of factorial hence we used z

Delete