0

799views

What is function? Write a C program to calculate factorial of a given number.

**1 Answer**

0

799views

What is function? Write a C program to calculate factorial of a given number.

0

106views

written 13 months ago by |

*Function:*

- A function is defined to be a self-contained program which is written for the purpose of accomplishing some task.
- Function is reusable block of code that makes a program easier to understand, test and can be easily modified without changing the calling program.

**C program to find factorial :-**

void factorial (int)

void main()

{

int number;

int fact;

printf(“Enter a number:”)

scanf(“%d”, &number);

fact=factorial(number);

printf(“factorial of %d is %d \n”number,fact);

}

void factorial(int n)

{

if (n==0)

return 1;

else

return (n*factorial(n-1));

}

ADD COMMENT
EDIT

Please log in to add an answer.