Factorial

Description:           This program find the factorial of a given number.

 
Primary Inputs:    Number

Primary Output:    Factorial of the given number

Platform Used:      Turbo C++ version 3.0, Borland International Inc.
 

/*program to find factorial of a number*/

#include
#include

/*prototype declaration of a function*/

unsigned long int fact(int);

void main()
{
int x;
char another='y';
unsigned long int f;
clrscr();
while(another=='y')
{
printf("\nenter the no. to find the factorial:");
scanf("%d",&x);
f=fact(x);
printf("\nfactorial of %d is %lu",x,f);
printf("\nWant to enter another no. y/n\n");
scanf("%s",&another);
}
getch();
}

unsigned long int fact(int m)
{
int n;
if(m==0||m==1)
return 1;
else
n= m * (fact(m-1));
return n;
}

Rate this post

Leave a Reply