Question

PLEASE WRITE IN C# Problem: Summing up sums. For this question, you’ll understand the importance of...

PLEASE WRITE IN C#

Problem: 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?

Example Output using {5, 18, 4, 7, 11}:

136

Example Output using {50, 19, 1, -49, 3, 99, 3, 21, 63}:

1260

PLEASE WRITE IN C#

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.


using System;
class HelloWorld {
public static int sumOfSums(int[] arr, int k) {

if (k == 0) {

return arr[0];

}

return arr[k] * (k + 1) + sumOfSums(arr, k-1);

}
static void Main() {
int[] arr = {5, 18, 4, 7, 11};
Console.WriteLine(sumOfSums(arr, arr.Length - 1));
int[] arr1 = {50, 19, 1, -49, 3, 99, 3, 21, 63};
Console.WriteLine(sumOfSums(arr1, arr1.Length - 1));

}
}

M Inbox - gurkaranpreets x C PLEASE WRITE IN C# Pr X Online C# Compiler-o X <RVNL (NSE) 23.85 - Kite x C Expert Q&A | Chegg.c

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
PLEASE WRITE IN C# Problem: Summing up sums. For this question, you’ll understand the importance of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help writing these functions in C programming. Write a C function that checks if...

    I need help writing these functions in C programming. Write a C function that checks if an array is sorted or not using an iterative approach. Write a C function that checks if an array is sorted or not using a recursive approach Write a C function to reverse the elements of an array. Note you are not allowed to use an 1. additional array to do that Write a C function to find the sum of the elements of...

  • IN MATLAB RECURSIVE FUNCTION 1. Sum of Factorials. The Recursive Function: A series that sums up...

    IN MATLAB RECURSIVE FUNCTION 1. Sum of Factorials. The Recursive Function: A series that sums up the factorial of the natural numbers from 1 to N can be expressed as The recursive algorithm: N-1 N-2 N-3 Write independent matlab code to solve the above problem with the following methods: 1. 2. 3. A monolithic program (with no functions) A standard (non-recursive) user defined function (an a program to call it) A recursive function (an a program to call it) Test...

  • Please help me! For Problem 1, 2 and 3: You are required to submit three .c...

    Please help me! For Problem 1, 2 and 3: You are required to submit three .c files that contain the instructions that you have written to solve the following problems. Place the C source code to solve the first problem in a file called lab5a.c. Place the C source code to solve the second problem in a file called lab5b.c. And place the C source code to solve the third problem in a file called lab5c.c. Remember to include your...

  • Write a C++ function that prints an array, skipping over a number of elements. Use the...

    Write a C++ function that prints an array, skipping over a number of elements. Use the following header: void printArraySkip(int array[], int elems, int skip) { } Where 'array' is an input array of 'elem' integer elements, and 'skip' is the number of elements to skip over. For example, if the function is called like this: int array[6] = { 5, 7, 11, 12, 18, 19 }; printArraySkip(array, 6, 2); The output would be: 11 19 in c++. Thanks

  • Write a program in Python that approximates the value of π by summing the terms of...

    Write a program in Python that approximates the value of π by summing the terms of this series: 4/1-4/3 + 4/5- 4/7 + 4/9- 4/11 + ... The program should prompt the user for n, the number of terms to sum, and then output the sum of the first n terms of this series. Have your program subtract the approximation from the value of math. pi to see how accurate it is.

  • Write a mips program that defines two integer array that are pre-sorted and the same size...

    Write a mips program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6,...

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Please solve this question using c++ language Problem 2. More Probleml. The program builds the array...

    Please solve this question using c++ language Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find the sum of all unique elements in the array using a function findUniqueSum Arrays Write a program that as before asks the user to enter input as in оn Sample Input/Output Enter a list of numbers ending with -999 3 1 4 55-999 The sum of unique numbers is: 13 Enter a list...

  • l ask Write a C++ program that accomplishes the following tasks 1. Write a function that...

    l ask Write a C++ program that accomplishes the following tasks 1. Write a function that finds the average of current element and the next element in given array named as "elements" and stores the new found averages into another array called "averageArray". Note: For the last element you can just divide the value of last element by 2 Write a function that takes both the given array and average array you just created along with a variable "productofArrays" using...

  • Create a program in C where pipes are used. The program's execution line should indicate the...

    Create a program in C where pipes are used. The program's execution line should indicate the number of children and the elements of an array that will compute their sums. The number of children can only be 1, 2, or 3. ./myprogram 3 1 2 3 4 6 12 (3 indicates the number of children in the array) Example for executing in linux terminal:Assuming parent has pid 5, child one has pid 6, child two has pid 7, and child...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT