Google Ads

Wednesday, May 27, 2009

Factorial


FACTORIAL OF A NUMBER


#include”stdio.h”

#include “conio.h”

long int fact(int);

void main()

{

int n;

clrscr();

printf("\nEnter the value : ");

scanf("%d",&n);

printf("\nThe Factorial of %d : %ld",n,fact(n));

getch();

}

long int fact(int n)

{

if((n==0)||(n==1))

return(1);

else

return(n*fact(n-1));

}

Output will be


Enter the value : 5

The Factorial of 5 : 120

No comments:

Post a Comment