online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <stdio.h> int swap_times = 0; void selectionSort(int arr[], int n) { for (int i = 0; i < n - 1; i++) { // Assume the current position holds // the minimum element int min_idx = i; // Iterate through the unsorted portion // to find the actual minimum for (int j = i + 1; j < n; j++) { if (arr[j] < arr[min_idx]) { // Update min_idx if a smaller element is found min_idx = j; } } // If a new minimum is found, // swap it with the element at index i if (min_idx != i) { int temp = arr[i]; arr[i] = arr[min_idx]; printf("%d is swapping with %d\n", temp, arr[i]); arr[min_idx] = temp; swap_times++; } } } void printArray(int arr[], int n) { for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } printf("\n"); } int main() { int arr[] = {3,1,4,2}; int n = sizeof(arr) / sizeof(arr[0]); printf("Original array: "); printArray(arr, n); selectionSort(arr, n); printf("Sorted array: "); printArray(arr, n); printf("swapped %d times\n", swap_times); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue