Sort {5,1,4,2,8} using bubble sort and print.
Toolliyo Coach
Progressive help: Nudge → Guide → Approach. Full solution stays behind the Solution tab.
Editor is open — no login wall to practice.
| Test | Status | Details |
|---|
Ready — edit the code above and click Run or Submit.
using System;
class Program
{
static void Main()
{
int[] arr = { 5, 1, 4, 2, 8 };
for (int i = 0; i < arr.Length - 1; i++)
for (int j = 0; j < arr.Length - 1 - i; j++)
if (arr[j] > arr[j + 1])
(arr[j], arr[j + 1]) = (arr[j + 1], arr[j]);
Console.WriteLine(string.Join(", ", arr));
}
}
Prefer Coach (Nudge → Guide → Approach) before revealing. No forced signup.
Bubble sort is O(n²)—know it for interviews even if you use Array.Sort in production.
Sign in to save and review your submission history. You can still Run code on the Editor tab as a guest.
Sign in