0
1.3kviews
What is function? Write a C program to calculate factorial of a given number.
1 Answer
0
130views

Function:

  1. A function is defined to be a self-contained program which is written for the purpose of accomplishing some task.
  2. 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 :-

#include< stdio.h >

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));

}

Please log in to add an answer.