EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 5, Problem 13E
Program Plan Intro

Recursive method:

  • A method calls itself is as recursive method.
  • In recursive function base case will stop recursion and return value instead of calling function.

Program to implement:

  1. a. Recursive functions for John Napier’s Method to print logarithms.
  2. b. Modified recursive function to find logarithm of a specific number between “100” and “1000”.
  3. c. Function to call above function to find logarithm of a number not between “100” and “1000”.

Explanation of Solution

//b. Modified recursive function to find logarithm of a number between 100 and 1000:

//Recursive function to find logarithms of a number between 100 and 1000

void logarithmOf(double first, double second, double firstLog, double secondLog,double num)

{

//If difference between adjacent numbers is greater than tolerance

if (fabs(first - second) > tolerance)

//If number is less than square root of (first*second)

if (num < sqrt(first*second))

//Function calls itself recursively with parameters first,sqrt(first*second),firstLog,(firstLog+secondLog)/2 and num

logarithmOf(first,sqrt(first*second),firstLog,(firstLog+secondLog)/2,num);

//If number is greater than or equal to square root of (first*second)

  else

//Function calls itself recursively with parameters sqrt(first*second),second,(firstLog+secondLog)/2,secondLog and num

logarithmOf(sqrt(first*second),second,(firstLog+secondLog)/2,secondLog,num);

//If difference between adjacent numbers is less than or equal to tolerance

else

//Print logarithm of number

cout << "log(" << num << ") = " << firstLog <�...

Explanation of Solution

//c. Function to call modified function to find logarithm of a number not between 100 and 1000:

//Function to find logarithm of number does not between 100 and 1000

void newlogarithm(double first, double second, double firstLog, double secondLog,double num)

{

  //If number is less than 10^2 and greater than 10^3

  if (num < pow(10.0,2) || num > pow(10.0,3))

  //Call function  logarithmOf()

logarithmOf(first, second, firstLog, secondLog,num);

  //If number is between 100 and 1000

  else

  //Print error message

  cout<<"Input is invalid"<<endl;

}

//Program begins with main() function

int main()

{

  //Declare variable

  int num;

  //Call recursive function logarithm()

  cout<<"Result of function logarithm(): "<<endl;

  logarithm(2,6,0.3010,0.778);

  //Prompt and read number from user

  cout<<"Enter number between 100 and 1000: "<<endl;

  cin>>num;

  //If number is between 100 and 1000

  if(num>100 && num<1000...

Blurred answer
Students have asked these similar questions
Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a function A(m, n) that solves Ackermann’s function. Use the following logic in your function: If m = 0 then return n + 1 If n = 0 then return A(m-1, 1) Otherwise, return A(m-1, A(m, n-1)) Test your function in a driver program that displays the following values:A(0, 0) A(0, 1) A(1, 1) A(1, 2) A(1, 3) A(2, 2) A(3, 2)
java C++ Ackermann’s FunctionAckermann’s Function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a function A(m, n) that solves Ackermann’s Function. Use the following logic in your function:If m = 0 then return n + 1If n = 0 then return A(m−1, 1) Otherwise, return A(m−1, A(m, n−1))Test your function in a driver program that displays the following values:A(0, 0) A(0, 1) A(1, 1) A(1, 2) A(1, 3) A(2, 2) A(3, 2) SAMPLE RUN #0: ./AckermannRF         Hide Invisibles Highlight: Show Highlighted Only  The·value·of·A(0,·0)=·1↵ The·value·of·A(0,·1)=·2↵ The·value·of·A(1,·1)=·3↵ The·value·of·A(1,·2)=·4↵ The·value·of·A(1,·3)=·5↵ The·value·of·A(2,·2)=·7↵ The·value·of·A(3,·2)=·29↵
Write a recursive mathematical definition for computing for a positive integer n.
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