77.5k views
1 vote
The "odd/even factorial" of a positive integer n is represented as n and is defined non-recursively as: (n)(n-2)(n-4)...(4)(2) if n is even and is (n)(n-2)(n-4)...(5)(3) (1) if n is odd. For example 7 equals 7*5*3*1 or 105 and 6 equals 6*4*2 or 48. Come up with a recursive definition for n and use it to guide you to write a method definition for a method called oddevenfact that recursively calculates the odd/even factorial value of its single int parameter. The value returned by oddevenfact is a long..

User Mrowe
by
6.5k points

1 Answer

6 votes

Answer:

The function definition to this question can be described as follows:

long oddevenfact(int y) //defining a method oddevenfact

{

//defining conditional statement

if (y>2) //check value is greater then 2

{

return( oddevenfact(y-2) * (long) y); //return value

}

else //else

{

return((long) y); //return its value

}

}

Step-by-step explanation:

The description of the above method definition can be described as follows:

  • In the above method definition a long method "oddevenfact" is declared, which accepts an integer variable "y" as its arguments, and return value as long.
  • Inside the method, a conditional statement is used, in if the block, it checks a value, that is value is greater then 2, and inside the block, a recursive function is used, that calculates its factor, and returns its value in long type.
  • If the condition is not true, it will go to else block and return in long type value.
User Merc
by
6.4k points