You cannot copy content of this page.

Program to compute factorial of a given number

Program to compute factorial of a given number



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