#include<stdio.h>
#include<conio.h>
void main()
{
int n, fact;
clrscr();
printf("\nEnter a Number: ");
scanf("%d",&n);
fact = factorial(n);
printf("\nThe Factorial value is: ");
printf("%d",fact);
getch();
}
factorial(int n)
{
int fact;
if(n==1)
{
return(1);
}
else
{
fact = n * factorial(n-1);
return fact;
}
}
Output:
Enter the value: 5
The Factorial value is: 120
#include<conio.h>
void main()
{
int n, fact;
clrscr();
printf("\nEnter a Number: ");
scanf("%d",&n);
fact = factorial(n);
printf("\nThe Factorial value is: ");
printf("%d",fact);
getch();
}
factorial(int n)
{
int fact;
if(n==1)
{
return(1);
}
else
{
fact = n * factorial(n-1);
return fact;
}
}
Output:
Enter the value: 5
The Factorial value is: 120
Comments
Post a Comment