PROGRAM TO FIND FACTORIAL OF A NUMBER USING FUNCTIONS

/*PROGRAM TO FIND FACTORIAL OF A NUMBER USING FUNCTIONS*/
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int n,f;
clrscr();
printf(“Enter any integer whose factorial is to be calculated: “);
scanf(“%d”,&n);
if(n>0)
{
f=fact(n);
printf(“Factorial of %d is %d”,n,f);
}
else
printf(“Factorial of numbers less than 1 does not exist”);
getch();
}
int fact(int n1)
{
int f1=1,i;
for(i=n1;i>=1;i–)
f1=f1*i;
return(f1);
}

Leave a Reply

Your email address will not be published. Required fields are marked *