Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a program to sort an array using the bubble sort algorithm.

Hard

Problem Statement

Write a program to sort an array using the bubble sort algorithm.

Sample Input

int arr[] = {5, 2, 9, 1};

Sample Output

Sorted array: 1 2 5 9 

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <iostream> void bubbleSort(int arr[], int size); int main() { // Logic to demonstrate bubble sort return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
int arr[] = {5, 2, 9, 1};
Expected Output
Sorted array: 1 2 5 9