Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 13, Problem 7PE
Program Plan Intro

Computing efficiency

Program plan:

  • Import required files.
  • Call the function “setrecursionlimit()” to set limit.
  • Define a function “factorial()”.
    • Set the value of “fact” equal to 1
    • Iterate a for loop.
      • Set the value of “fact”.
    • Return the value of “fact”.
  • Define a function “iterative_options()”.
    • Declare a variable “x” and set with value of “factorial(n)”.
    • Declare a variable “x” and set the value.
    • Return the value “x/y”.
  • Define a function “recursive_options()”.
    • If the condition “k == 1”is true.
      • set the value of “options” as n.
    • Checking another condition “n < k”.
      • set the value of “options” as 0.
    • If the conditions failed.
      • Set the value of options using function “recursive_options()”.
      • Return the value of “options”.
  • Define the “main()” function.
    • Print the value using “iterative_options()”.
    • Print the value using “recursive_options()”.
  • Call the “main()” function.

Blurred answer
Students have asked these similar questions
The “odd/even factorial” of a positive integer n is represented as n!! and is defined recursively as: a. (n)*(n-2)*(n-4)………*(2) if n is even. For example, 6!! = 6*4*2 = 48 b. (n)*(n-2)*(n-4)*…….*(5)*(3)*(1) if n is odd. For example, 7!! = 7*5*3*1 = 105. 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.
In mathematics, a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers, i.e. is it has only two factors 1 and itself. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself.Note that the prime number series is: 2, 3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, …a. Write a Java method named isPrime that takes a natural number as a parameter and returns the if the given number is prime or not using the following header: Public static boolean isPrime(int num) b. Write a Java class called PrimeNumbers that: o Reads from the user a natural value n (should be less than or equal 200). o Prints a list of the prime numbers from 2 to n and their number and values. o The program has to work EXACTLY as given in the following sample run.
One of the most common examples of recursion is an algorithm to calculate the factorial of an integer. The notation n! is used for the factorial ofthe integer n and is defined as follows:0! is equal to 11! is equal to 12! is equal to 2 × 1 = 23! is equal to 3 × 2 × 1 = 6
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License