Program
#include<stdio.h>
int fact(int);
void main()
{
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
}
int fact(int n)
{
if(n==1)
return 1;
else
return(n*fact(n-1));
}
Output
Enter a number: 5
Factorial of 5 is: 120
#include<stdio.h>
int fact(int);
void main()
{
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
}
int fact(int n)
{
if(n==1)
return 1;
else
return(n*fact(n-1));
}
Output
Enter a number: 5
Factorial of 5 is: 120
No comments:
Post a Comment