Program to calculate the factorial of a given number using function


Program to calculate the factorial of a given number using funion

#include <stdio.h>
#include <conio.h>

int factorial(int); //Function is declared which has int datatype and int as argument

void main()
{
int n;
int result=0;

clrscr();

printf("Enter the number : ");
scanf("%d",&n);

result=factorial(n); //funion call

printf("factorial is : %d", result);

getch();
}

int factorial(int n) //function definition
{
int i;
int fact = 1;

for( i = 1 ; i <= n ; i++ )
{
fact = fact*i;
}
return ( fact );
}


Output :

0 comments:

Post a Comment