Coding:
#include<stdio.h>
#include<conio.h>
long fact(long);
void main()
{
int i;long f;
/* Initialization for Factorial without using Recursion
int i,n;
long f=1; */
clrscr();
printf("\nEnter the number: ");
scanf("%d",&i);
f=fact(i);
/* Factorial without using Recursion
for(n=1;n<=i;n++)
f*=n; */
printf("\nFactorial of %d is %ld",i,f);
getch();
}
long fact(long k)
{
if(k==0)
return 1;
else
return k*(fact(k-1));
}
Output:
No comments:
Post a Comment