Question

In: Computer Science

In C# Problem 1: Order matters! For this question, you’re going to write two recursive functions,...

In C# Problem 1: Order matters! For this question, you’re going to write two recursive functions, both of which take in only a single string as a parameter; you will not receive credit if you pass in an integer as well. Note: you will need to understand substrings to get the correct solution. The first function should simply print out the string, but do so letter by letter – and recursively. The second function should print out the string in reverse; the code is almost identical, but the concept is different. Hint, note the title of the problem. Example Output: Hello world! !dlrow olleH

Problem 2: Summing up sums. For this question, you’ll understand the importance of using the results of smaller sets of work. You’re going to create a recursive function that takes in an array of random integers and returns a “sum of sums”. This is best explained through an example. If you have 5 elements in an array, the function should return the sum of elements 0-4, 1-4, 2-4, 3-4, and 4. So, if we had an array of: 5, 18, 4, 7, 11 The sum of sums would be (45+40+22+18+11) = 136. Hint: is the sum of sums not just the sum of the current array + the sum of sums of an array?

Solutions

Expert Solution

using System;

class MainClass {

  public static void func1 (string x) {
          if(x.Length != 0) {
                Console.Write(x[0]);
                func1(x.Substring(1));
          }
  }
  public static void func2 (string x) {
          if(x.Length != 0) {
                func2(x.Substring(1));
                Console.Write(x[0]);
          }
  }

  public static void Main (string[] args) {
    func1("hello world!");
    Console.Write(" ");
    func2("hello world!");
  }
}
**************************************************

Answering your first question, as the questions are completely unrelated and require different code. I request you to please post single question in a thread, so that it helps us in explaining the things better to you. Hope you understand!

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

PYTHON PYTHON Recursive Functions. In this problem, you are asked to write three recursive functions. Implement...
PYTHON PYTHON Recursive Functions. In this problem, you are asked to write three recursive functions. Implement all functions in a module called problem1.py. (10 points) Write a recursive function called remove char with two parameters: a string astr and a character ch. The function returns a string in which all occurrences of ch in astr are removed. For example, remove char("object oriented", ’e’) returns the string "objct orintd". Your implementation should not contain any loops and may use only the...
C++ Recursive Functions: Please call functions in a main function as well. 1. A recursive function...
C++ Recursive Functions: Please call functions in a main function as well. 1. A recursive function that print the reverse of a string. (e.g., void printReverse(string exp)). For example, if exp =”coding”, then the function should print out “gnidoc”. 2. Implement a non-recursion-based binary search function. Convert this function into a recursion-based function. 3. Implement a recursive and non-recursive Fibonacci function.
Can you answer these question using python and recursive functions Write a function that consumes two...
Can you answer these question using python and recursive functions Write a function that consumes two numbers N1 and N2 and prints out all the even numbers between those numbers, using recursion. Using any number of list literals of maximum length 2, represent the data from your Survey List. So you cannot simply make a list of 15 values. Make a comment in your code that explicitly describes how you were able to represent this. Write a recursive function that...
C# PLEASE Lab7B: For this lab, you’re going to write a program that prompts the user...
C# PLEASE Lab7B: For this lab, you’re going to write a program that prompts the user for the number of GPAs to enter. The program should then prompt the user to enter the specified number of GPAs. Finally, the program should print out the graduation standing of the students based on their GPAs. Your program should behave like the sample output below. Sample #1: Enter the number of GPAs: 5 GPA #0: 3.97 GPA #1: 3.5 GPA #2: 3.499 GPA...
For this problem you must write the functions in a recursive manner (i.e. the function must...
For this problem you must write the functions in a recursive manner (i.e. the function must call itself) – it is not acceptable to submit an iterative solution to these problems. A. Complete the recursive function gcd(m, n) that calculate the greatest common denominator of two numbers with the following rules: # If m = n, it returns n # If m < n, it returns gcd(m, n-m) # If m > n, it returns gcd(m-n, n) # def gcd(m,n):...
In C++, please check for memory leaks Recursive Functions Goals Create and use recursive functions In...
In C++, please check for memory leaks Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character. Example: Input of “Hello,...
C++ Create a recursive program what will test three recursive functions. It would have a menu...
C++ Create a recursive program what will test three recursive functions. It would have a menu like: 1. Recursive factorial 2. Towers of Hanoi 3. Recursive summation 0. Exit Enter selection: 3 Enter number: 4 The recursive summation will take an integer and sum value from 1 to the integer. Don’t enter a number if the selection is 0 for quit. Please have the functions in an implementation file and the prototypes of the functions in a header file and...
write both non-recursive and recursive functions that take the strings from the user and display strings...
write both non-recursive and recursive functions that take the strings from the user and display strings in backwards in python
1) a. Write a C++ program for the recursive algorithm that removes all occurrences of a...
1) a. Write a C++ program for the recursive algorithm that removes all occurrences of a specific character from a string b. Write the pseudocode for the program.
c++ Write a program that displays the status of an order. a) Program uses 2 functions...
c++ Write a program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT