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
Lab 07: Java Graphics (Bonus lab) In this lab, we'll be practicing what we learned about GUIs, and Mouse events. You will need to implement the following: ➤ A GUI with a drawing panel. We can click in this panel, and you will capture those clicks as a Point (see java.awt.Point) in a PointCollection class (you need to build this). о The points need to be represented by circles. Below the drawing panel, you will need 5 buttons: о An input button to register your mouse to the drawing panel. ○ о о A show button to paint the points in your collection on the drawing panel. A button to shift all the points to the left by 50 pixels. The x position of the points is not allowed to go below zero. Another button to shift all the points to the right 50 pixels. The x position of the points cannot go further than the You can implement this GUI in any way you choose. I suggest using the BorderLayout for a panel containing the buttons, and a GridLayout to hold the drawing panel and button panels.…
If a UDP datagram is sent from host A, port P to host B, port Q, but at host B there is no process listening to port Q, then B is to send back an ICMP Port Unreachable message to A. Like all ICMP messages, this is addressed to A as a whole, not to port P on A. (a)  Give an example of when an application might want to receive such ICMP messages. (b)  Find out what an application has to do, on the operating system of your choice, to receive such messages. (c)  Why might it not be a good idea to send such messages directly back to the originating port P on A?
Discuss how business intelligence and data visualization work together to help decision-makers and data users. Provide 2 specific use cases.
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