Write a recursive function to compute the product of all odd

Write a recursive function to compute the product of all odd numbers smaller than a given number. That is if the function is called with 6, it will return 1*3*5=15.

Solution

Answer:

C Program :

#include<stdio.h>

int main(){

int number;
  
int product =1;
int n;
printf(\"Enter any number to which the product must be computed:\");
scanf(\"%d\", &n);

for(number = 1;number<=n; number++)
if(number % 2 !=0)
product = product * number;

printf(\"Product of odd numbers is:%d\",product);

return 0;

}

Output:

Enter any number to which the product must be computed:6

Product of odd numbers is: 15

 Write a recursive function to compute the product of all odd numbers smaller than a given number. That is if the function is called with 6, it will return 1*3*

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site