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 program which reads data into type integer

Write down the program which reads data into type int. Valid values are from 0 to 10. The program must find out how many values were inputted.

  Write the program which processes test data

Write the program which processes test data. Output must be student's ID, followed by answers, followed by test score, followed by test grade. Suppose the following grade scale.

  Write program to decodes messages using caesar cypher

Write a program which decodes messages. Messages will be encoded using Caesar cypher, with each letter being decoded by replacing it with the previous letter in the alphabet.

  Writes a function that takes a list of integers

Using ML writes a function that takes a list of integers as argument and returns a pair consisting of the sum of the even position and the sum of the odd positions of the list. You should not use auxiliary functions

  Write a script that inputs a numeric check amount

Write a script that inputs a dollar amount to be printed on a check, then prints the amount in check protected format with leading asterisks if necessary. Assume that nine spaces are available for printing the amount.

  File processing commands worksheet

File Processing Commands Worksheet. What UID and PID have the highest amount of physical memory a process has used and is not swapped out? Show all processes and full output.

  Writing application to accept loan amount-interest rate

Write down the application to accept a loan amount, annual interest rate, and loan period (in number of years) and displays a table with five columns.

  Program to display words in a list box sorted by number

Write a program to display the words in a list box sorted by the number of different vowels(a,e,i,o,u) in the word.

  Write a full program to convert seconds into hours

Write a full program (starting from #include) that takes as input the number of seconds after midnight and displays the time in hours.

  Write program that merges two files

The first programming project involves writing a program that merges two files that contain polynomials. To merge two files, the input files must be in sorted order.

  Program to convert temperature in celcius from fahrenheit

Write the program which accepts the temperature in Fahrenheit from user and conversts it to Celsius by subtracting 32 from Fahrenheit value and multiplying result by 5/9. Show both values.

  Write a method mincat that takes two strings s and t and

write a method mincat that takes two strings s and t and returns a new string. the returned string contains the

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