Below is the recursive implementation of the code. Comments are added in the code itself. The logic of the code is a recursive function which is being executed in a bottom-up manner. The recursive function has two parts, one is the base case which handles the termination of the recursion properly and other is the normal recursion. Fin below the code, the screenshot of the code and the desired output. Try to dry run the code on a paper to understand the logic.
Code
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
void asterisk_recur(int n,int c)
{
// Base case or Termination case
if(n==1)
{
// appending the space
characters
for(int i=0;i<c;i++)
cout<<"
";
cout<<"*";
}
else
{
asterisk_recur(n/2,c);
cout<<"\n";
// appending the space
characters
for(int it=0;it<c;it++)
cout<<" ";
// print the
asterisks
for(int
it=0;it<n;it++)
cout<<"* ";
cout<<"\n";
asterisk_recur(n/2,c+n);
}
}
// main function
int main()
{
// calling the recursive function to generate
pattern
asterisk_recur(8,0);
return 0;
}
Screenshot
Output
can anyone please help me to write a recursive ( must in recursive function) function in...
This is python coding recursive function question. Could anyone help me figuring out these not using built-in function? Thanks. Write a recursive function factorial(n) that returns the value of n!=1⋅2⋅3⋅⋯⋅n. 2. Write a recursive function reverse(text) that returns the reverse of the string named text. 3. Write a recursive function countUpper(s) that returns the number of uppercase letters in the string s. 4. Write a recursive function equal(list1, list2) that returns a Boolean value indicating whether the two lists are...
This is Python coding question, and topic is recursive. Can anyone help me figuring this out? (Only recursive function is allowed.) Thanks. Write a function called Fibonacci(n) that takes as a parameter an integer n and returns the nth Fibonacci number. The first two Fibonacci numbers are 1 and every subsequent one is the sum of the previous two: 1, 1, 2, 3, 5, 8, 13, .... Write a recursive function to count the number of uppercase letters in a...
Can anyone help me write a C function that goes through an input string and insert spaces(" ")infront and after "<",">","|"? For example: if my input string is: HELLO<WO|RLD>!, the output of the function will be a array like: HELLO < WO | RLD > ! Thanks!
Can anyone help me with this question? I am confused, please help me! Thanks. Light propagating in the glass n_1 = 1.50 wall of an aquarium tank strikes the interior edge of the wall with incidence angle 12.0 degree Part A What is the angle of refraction in the water (n = 1.333)?
Can anyone please help me solve this and include the steps on how to do it? Thanks! 7. An electron with velocity -4.10m/s enters a region with the uniform electric field E 12,0002 N/C. Calculate the deflection of the electron after it has traveled 2 cm in the î direction
Can anyone help me to calculate the determinant of the function using only setdiff function?
Can anyone please help me with the 2 questions below. Thanks in advance: 1. Critically analyse the role of competitive advantage in supply chain management, and how purchasing influences strategy. 2. Discuss how performance measurement of suppliers improves efficiency and develops competitive advantage, using examples of organisations to illustrate your answer. Thanks
Can anyone please help me with the 2 questions below. Thanks in advance: 1. Critically analyse the role of competitive advantage in supply chain management, and how purchasing influences strategy. 2. Discuss how performance measurement of suppliers improves efficiency and develops competitive advantage, using examples of organisations to illustrate your answer. Thanks
Please help me with this question Write a recursive method that returns the largest integer in an array. Write a test program that prompts the user to enter a list of eight integers and displays the largest largest element. Thank you! and can you give details so I know what is going on?
CAN ANYONE PLEASE HELP ME SOLVE THIS PROBLEM WITHOUT RETURNING ERRORS, BAD TOKENS, ETC. PLEASE INCLUDE CORRECT SYNTAX...MUST BE IN PYTHON 3 AND PASS THE TEST Write a function analyze_text that receives a string as input. Your function should count the number of alphabetic characters (a through z, or A through Z) in the text and also keep track of how many are the letter 'e' (upper or lowercase). Your function should return an analysis of the text in the...