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
how to know the weight to data and data to weight also weight by infomraion gain in rapid miner , between this flow diagram retrieve then selecte attrbuite then set role and split data and decision tree and apply model and peformance ,please show how the operators should be connected:
using rapid miner how to creat decison trea for all attribute and another one with delete one or more of them also how i know the weight of each attribute and what that mean in impact the result
Q.1. Architecture performance [10 marks] Answer A certain microprocessor requires either 2, 4, or 6 machine cycles to perform various operations. ⚫ (40+g+f)% require 2 machine cycles, ⚫ (30-g) % require 4 machine cycles, and ⚫ (30-f)% require 6 machine cycles. (a) What is the average number of machine cycles per instruction for this microprocessor? Answer (b) What is the clock rate (machine cycles per second) required for this microprocessor to be a "1000 MIPS" processor? Answer (c) Suppose that 35% of the instructions require retrieving an operand from memory which needs an extra 8 machine cycles. What is the average number of machine cycles per instruction, including the instructions that fetch operands from memory?
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