In: Computer Science
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?
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.