What is a recursive function

Assignment Help Programming Languages
Reference no: EM13936547

I have a question related to a recursive function. I have ran it and got it to do what it is supposed to. However, I don't fully understand how it is actually working and how it gets the answer

here is the function:
void G(char ch, int n)
{
if (n<=0)
cout<< endl;
else
{
G(ch-1, n-1);
cout<< ch;
G(ch-1,n-1);
}
}

in the main when you pass in G('M', 2) the print out is this;
L
M
L

when you pass in G('M',3) the print out is:
K
L
K
M
K
L
K

It seems to me it should read in the ch and n and then if n is not <= 0 it skips to G(ch-1, n-1) which seems like it would take M and subtract 1 and then n(2) and subtract one. If someone could take me through the recursive function step by step to show me how it gets the answer, that would be great.

Reference no: EM13936547

Questions Cloud

What is the selection coefficient for the tan allele : In the same population of rabbits, body mass is normally distributed with an average of 8 kg. Large rabbits stay warmer because they can better retain heat. After an especially cold winter, the average body mass of the breeding adult population wa..
Financial companies have immense discretion : The Motley Fool that more than any other type of company, financial companies have immense discretion regarding what earnings to report. The key is the rate of loan losses that they expect to experience, which must be estimated at the end of every pe..
How do we heal medicine : View Atul Gawande's TED Talk, How Do We Heal Medicine? Which of the models, cowboys or pit crews, would you advocate for as a healthcare manager? Provide some positives and negatives of each model.
Constructors need to be declared for each class. : Hi, I need helping figuring out the following questions. I need to identify the following statements as either true or false. If an answer is true, I need to explain why and, where appropriate, provide an example. If the answer is false, I also ne..
What is a recursive function : I have a question related to a recursive function. I have ran it and got it to do what it is supposed to. However, I don't fully understand how it is actually working and how it gets the answer
Primary advantage of revealed-­preference valuation methods : What is the primary advantage of revealed-­-preference valuation methods (e.g. hedonic pricing and travel-­-cost methods)? What is their primary disadvantage? Explain both answers briefly.
The rental company''s manager : The Assistant Manager meets with the Manager every day and hand delivers each reviewed complaint form to the Manager, and informs the Manager about any complaints that need additional review by the Manager. The rental company's Manager reviews the co..
Evaluate factors that would affect the validity of data set : Write a 700- to 1,050-word paper in which you: Explain why this is (or is not) a suitable sample of quantitative data for the business scenario. Evaluate the factors that would affect the validity of the data set
What types of receptors involved smell and detection motion : What types of receptors are involved in smell and detection of motion? Why did the sensation of the smell fade but not the rolling sensation? Why do you feel sick to your stomach while on the sailboat?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd