Question: C# 1. Given an array, return an array of positive values, where these values have been repeated exactly the number of times given by the

C#

1.

Given an array, return an array of positive values, where these values have been repeated exactly the number of times given by the respective value. There should always be an array. public int[] RepeatedTimes(int[] array) {

2.

Given an array with int values in any order, develop codes that will modify the given array so that it will start with negative values, followed by positive values, and then by zeros. Please note that a zero is neither a positive value or a negative value. The order of negatives and the order of positives are not important, but make sure that all the negative values must come before all the positive values and that the zeros must come after everything else. You will need to swap the elements directly in the same array, and do not create a new array. Do not sort the array. Time-complexity: O(n), Space-complexity: O(1).

public void NegativePositiveZero(int[] a)

{

3.

Given a single-dimensional array of integers, create a method that identifies and returns the smallest, absolute difference between an element and the average of its adjacent elements in the array. An element can have up to two adjacent elements. Throw ArgumentNullException if the input argument is null. Also throw InvalidOperationException if the input array only has one element or is empty (hint: what does it mean by an array is emptywhat is its length?). /// When array a is null /// When array a is empty or has only one element. An element can have up to two adjacent elements (one adjacent element if the element is in the beginning or at the end array).

The smallest, absolute difference between an element and the average of its adjacent elements.

public double ClosestAdjacent(int[] a)

{

4. Given a rectangular array of integers, create a method that identifies and returns the smallest, absolute difference between an element and the average of its surrounding elements in the matrix. Throw ArgumentNullException if the input argument is null. Also, throw InvalidOperationException if the input array only has one element or is empty (hint: whats an empty rectangular arraywhat are its lengths? For example, is 0 by 10 matrix empty?). An element can have up to 8 surrounding elements. Please note that it is better to use a loop rather than eight separate statements to calculate the surrounding average. /// When array a is null /// When array a is empty or has only one element.

public static double ClosestSurrounding(int[,] a) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!