Lovemore Kutseya

Lovemore Kutseya

  • NA
  • 21
  • 3.4k

array as parameters

Dec 19 2018 12:44 PM
write a Separate method should take an integer array and swap the element in that array until it contains the even numbers sorted followed by the odd number sorted.
For example and array containing 3, 4, 2, 1, 5 should end us as 2, 4, 1, 3, 5.
 
using System;

namespace HelloWorld
{
class Program
{
static string GetArrayAsString(int[] array)
{
if(array.Length == 0) return "";

string str = "";
int i = 0;
for(; i < array.Length - 1; i++)
{
str += array[i] + ", ";
}
str += array[i];

return str;
}

static void Main(string[] args)
{
int[] numbers = {3, 4, 2, 1, 5};
Separate(numbers);
Console.WriteLine(GetArrayAsString(numbers));
}
}

Answers (1)