This program calculate the factorial of given number.
Enter Number : 5
The Factorial of 5 is 120
factorial.c
include <stdio.h>
include<conio.h>
int fact(int n)
{
if(n == 0 | n == 1)
return 1;
else
return(n * fact(n - 1));
}
void main()
{
int n, result;
printf("Enter Number : ");
scanf("%d", &n);
result = fact(n);
printf("\n The factorial of %d is %d", n, result);
getch();
}
Output:include <stdio.h>
include<conio.h>
int fact(int n)
{
if(n == 0 | n == 1)
return 1;
else
return(n * fact(n - 1));
}
void main()
{
int n, result;
printf("Enter Number : ");
scanf("%d", &n);
result = fact(n);
printf("\n The factorial of %d is %d", n, result);
getch();
}
Enter Number : 5
The Factorial of 5 is 120
No comments:
Post a Comment