A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C# program to sort the integers in ascending order without moving the number -5
Q:

Write a C# program to sort the integers in ascending order without moving the number -5

0

Write a C# program to sort the integers in ascending order without moving the number -5

Sample Output:

-5
70
120
236
-5
-5
280
698

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
using System.Collections;

public class Example
    {
      public static int[] sort_numbers(int[] arra)
        {
     
            int[] num = arra.Where(x => x != -5).OrderBy(x => x).ToArray();
            int ctr = 0;

            return arra.Select(x => x >= 0 ? num[ctr++] : -5).ToArray();
        }
  
   public static void  Main()
        {
           int[] x = sort_numbers(new int[] {-5, 236, 120, 70, -5, -5, 698, 280 });
            foreach(var item in x)
             {
               Console.WriteLine(item.ToString());
              }
        }        
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now