Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Program to compute factorial of a given number

Program to compute factorial of a given number

October 2, 2012 Comments Off on Program to compute factorial of a given number By admin

Recursion

Program to compute factorial of a given number

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

/*Recursive Definition*/
/*int factorial(int n)
{if(n==0)
return 1;
else
return(n*factorial(n-1));
}
*/
/*Non-Recursive Definition*/

int factorial(int n)
{int i,res=1;
for(i=n;i>=1;i–)
res=res*i;
return(res);
}

void main()
{
int num,res;
clrscr();
printf(“nEnter number to compute factorial?”);
scanf(“%d”,&num);
res=factorial(num);
printf(“nFactorial = %d”,res);
getch();
}

Comments are closed
x Close

Like Us On Facebook

You cannot copy content of this page.