#include<stdio.h>
int fact(int);
void main()
{
int n,fac=1;
printf(“Enter any number”);
scanf("%d",&n);
fac=fact(n);
printf(“The Factorail of a given number%d”,fac);
}
int fact(int a)
{
if(a==1 || a==0)
return 1;
fact(a)=a*fact(a-1);
}
#include<stdio.h>
int fact(int);
void main()
{
int n,fac=1;
printf(“Enter any number”);
scanf("%d",&n);
fac=fact(n);
printf(“The Factorail of a given number%d”,fac);
}
int fact(int a)
{
if(a==1 || a==0)
return 1;
fact(a)=a*fact(a-1);
}
Hello, you made some logic/syntax erros;
you have to return a value in the fact function, instead of doing this fact(a)=a*fact(a-1)
you have to do return a * fact(a-1)
you don not have to check if the n is 0 if(n==1) return 1
is sufficient;
The factorial grows fast, so instead of returning int, return a long or long long …
And finally here is the code after some modifications
long fact(int);
int main() {
int n;
long fac=1;
printf("Enter any number");
scanf("%d",&n); fac=fact(n);
printf("The Factorail of a given number is : %ld",fac);
return 0;
}
long fact(int a) {
if(a==1) return 1;
return a*fact(a-1);
}