{"id":18184,"date":"2021-09-30T11:00:17","date_gmt":"2021-09-30T05:30:17","guid":{"rendered":"https:\/\/python-programs.com\/?p=18184"},"modified":"2021-11-22T18:35:32","modified_gmt":"2021-11-22T13:05:32","slug":"python-program-for-double-factorial","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-double-factorial\/","title":{"rendered":"Python Program for Double Factorial"},"content":{"rendered":"
In the previous article, we have discussed Python Program for Product of Maximum in First array and Minimum in Second<\/a> The product of all positive integers less than or equal to n is the factorial of a non-negative integer n, denoted by n! in mathematics:<\/p>\n n! = n * (n – 1) *(n – 2) * . . . . . . . . . . 3 * 2 * 1.<\/strong><\/p>\n 4 != 4 * 3 * 2 *1=24<\/p>\n Double Factorial:<\/strong><\/p>\n The product of all the integers from 1 to n with the same parity (odd or even) as n is the double factorial of a non-negative integer n. It is also known as a number’s semi factorial and is denoted by!!.<\/p>\n For example, the double factorial of 7 is 7*5*3*1 = 105<\/strong><\/p>\n It is worth noting that as a result of this definition, 0!! = 1.<\/p>\n The double factorial for even number ‘n’ is:<\/p>\n <\/p>\n The double factorial for odd number ‘n’ is:<\/p>\n <\/p>\n Given a number ‘n’ and the task is to find the double factorial of a given number.<\/p>\n Examples:<\/strong><\/p>\n Example 1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to find the double factorial of a given number.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program for Product of Maximum in First array and Minimum in Second Factorial: The product of all positive integers less than or equal to n is the factorial of a non-negative integer n, denoted by n! in mathematics: n! = n * (n – 1) *(n – …<\/p>\n
\nFactorial:<\/strong><\/p>\nGiven number = 5<\/pre>\n
The double factorial of a given number{ 5 } = 15<\/pre>\n
Given number = 10<\/pre>\n
The double factorial of a given number{ 10 } = 3840<\/pre>\n
Program for Double Factorial in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\nnumbr = 8\r\n# Take a variable, initialize it with the value '1', and store it in another\r\n# variable say 'c'.\r\nc = 1\r\n# Loop from the given number to 0 in decreasing order with the stepsize of -2\r\n# using the for loop.\r\nfor i in range(numbr, 0, -2):\r\n # Inside the loop multiply the above initialized variable c with the iterator value\r\n # and store it in the same variable 'c'.\r\n c *= i\r\n # Print the double factorial of a given number.\r\nprint(\"The double factorial of a given number{\", numbr, \"} = \", c)\r\n<\/pre>\n
The double factorial of a given number{ 8 } = 384<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
# Give the number as user input using the int(input()) function and store it in a variable.\r\nnumbr = int(input(\"Enter a random number = \"))\r\n# Take a variable, initialize it with the value '1', and store it in another\r\n# variable say 'c'.\r\nc = 1\r\n# Loop from the given number to 0 in decreasing order with the stepsize of -2\r\n# using the for loop.\r\nfor i in range(numbr, 0, -2):\r\n # Inside the loop multiply the above initialized variable c with the iterator value\r\n # and store it in the same variable 'c'.\r\n c *= i\r\n # Print the double factorial of a given number.\r\nprint(\"The double factorial of a given number{\", numbr, \"} = \", c)\r\n<\/pre>\n
Enter a random number = 7\r\nThe double factorial of a given number{ 7 } = 105<\/pre>\n
\n