我尝试编写下面的程序。但是它没有工作。如果x是偶数则x值是正值 if和for x是奇数,它是else。我是编程新手:
gam<-function(x){
if as.numeric(x%%==0){
ans<- factorial((x/2)-1)
}
else
{
ans<- factorial(x-1)/2^(x-1)*factorial((x/2)-(1/2))
}
return(ans)
}
任何人都可以帮助我吗?
答案 0 :(得分:-1)
你的问题是你错过了
if (x%%2==0)
可能是你想要的东西:
gam<-function(x){
if (x%%2==0){
ans<- factorial((x/2)-1)
}else{
ans<- factorial(x-1)/2^(x-1)*factorial((x/2)-(1/2))
}
return(ans)
}
只需输入gam(2)或gam(3)等。