Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can someone do it asap Lab 10 - Recursion and the Divide-and-Conquer Paradigm The goal of this lab is to explore recursion and the divide-and-conquer
can someone do it asap
Lab 10 - Recursion and the Divide-and-Conquer Paradigm The goal of this lab is to explore recursion and the divide-and-conquer paradigm. Specifically, the lab introduces recursion using a naturally recursive formula to generate the harmonic series and demonstrates the divide-and-conquer paradigm ti h binary search and the merge sort PartI- Recursion Example: The Harmonic Series 23 45 The harmonic series comes from the concept of overtones. also known as harmonics, in music. Harmonics represent the wavelengths of a vibrating string. Every term after the first term is the harmonic mean of itself with the previous and next term. For example, the second term, 1/2, is the harmonic mearn of 1, 1/2, and 1/3, and the third term. 1/3, is the harmonic mean of 1/2, 1/3, and 1/4. It is a divergence series that is oftern explained through apparent paradoxes such as the "ant on the rope" or "Peterburg's Paradox" It is easy to generate and can be generated using a loojp however, it does have a natural recursive solution. Each term has a denominator of one more than the previous term's denominator. Let's write code for the recursive solution for practice and sum the series generated. Create a directory called 1040Lab10. Within this directory, create a file called harmonic.cpp and open the file for editing. Include the stdio (or C++iostream) and stdlib libraries and set up your main function without contents except for the return statement. Compile the program and fix any erTors. 1. 2. Recursively defined problems have a base case which defines when to stop the recursive process. For generating our series, let's generate a user specified amount of terms. In other words, the base case is when we have generated some number of terms. We will need to prompt the user for this value using pri declare an integer variable and prompt the user. Since we are going to sum the series, we can also go ahead and declare the variable to hold the sum and include a statement to print this sum. Notice that there is room left for calling the harmonic function that generates the series ntf and then use scanf to read it. Add the code below to your main function to int main() int base=0; // recursive base ca se float sum-0 // sum of the generated series // prompt the user for base case printf("Enter the number of terms to generate: ") scanf("%d", &base); //call the harmonic function REMOVE THIS LINE LATER AND PLACE THE FUNCTION CALL HERE // print the printf ("Sun: sum of %f ", the series sum); return 0; Page 1 of 8 Lab 10 - Recursion and the Divide-and-Conquer Paradigm The goal of this lab is to explore recursion and the divide-and-conquer paradigm. Specifically, the lab introduces recursion using a naturally recursive formula to generate the harmonic series and demonstrates the divide-and-conquer paradigm ti h binary search and the merge sort PartI- Recursion Example: The Harmonic Series 23 45 The harmonic series comes from the concept of overtones. also known as harmonics, in music. Harmonics represent the wavelengths of a vibrating string. Every term after the first term is the harmonic mean of itself with the previous and next term. For example, the second term, 1/2, is the harmonic mearn of 1, 1/2, and 1/3, and the third term. 1/3, is the harmonic mean of 1/2, 1/3, and 1/4. It is a divergence series that is oftern explained through apparent paradoxes such as the "ant on the rope" or "Peterburg's Paradox" It is easy to generate and can be generated using a loojp however, it does have a natural recursive solution. Each term has a denominator of one more than the previous term's denominator. Let's write code for the recursive solution for practice and sum the series generated. Create a directory called 1040Lab10. Within this directory, create a file called harmonic.cpp and open the file for editing. Include the stdio (or C++iostream) and stdlib libraries and set up your main function without contents except for the return statement. Compile the program and fix any erTors. 1. 2. Recursively defined problems have a base case which defines when to stop the recursive process. For generating our series, let's generate a user specified amount of terms. In other words, the base case is when we have generated some number of terms. We will need to prompt the user for this value using pri declare an integer variable and prompt the user. Since we are going to sum the series, we can also go ahead and declare the variable to hold the sum and include a statement to print this sum. Notice that there is room left for calling the harmonic function that generates the series ntf and then use scanf to read it. Add the code below to your main function to int main() int base=0; // recursive base ca se float sum-0 // sum of the generated series // prompt the user for base case printf("Enter the number of terms to generate: ") scanf("%d", &base); //call the harmonic function REMOVE THIS LINE LATER AND PLACE THE FUNCTION CALL HERE // print the printf ("Sun: sum of %f ", the series sum); return 0; Page 1 of 8
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started