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
Describe three (3) Multiplexing techniques common for fiber optic links
Could you help me to know  features of the following concepts: - commercial CA - memory integrity - WMI filter
Briefly describe the issues involved in using ATM technology in Local Area Networks
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License