Answer:
long long int prodby2(int n) //function using for loop...
{
long long int prod=1;
for(int i=1;i<=n;i+=2)
{
prod*=i;
}
return prod;
}
long long int prodby2vectorized(int n) //function without the use of for loop..
{
if(n<=1)
return 1;
if(n%2 == 0)
n--;
else
{
return n*prodby2vectorized(n-2); //recursive call..
}
}
Step-by-step explanation:
Two functions are written above prodby2 uses for loop while prodby2vectorized uses recursion.Both the functions are of long long int type because product can be very large.In the for loop it starts from 1 and i is increased by 2 so that i is always an odd number.Storing the product in prod variable.
In second function I have used recursion if n is less than or equal to 1` the function will return 1.If n is even it will decrease n else recursively calculate the result.