online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> void swap(int* a, int* b) //function to swap 2 elements { int t = *a; *a = *b; *b = t; } int partition (int arr[], int low, int high) //subfunction for sorting { int pivot = arr[high]; int i = (low - 1); for (int j = low; j <= high- 1; j++) { if (arr[j] < pivot) { i++; swap(&arr[i], &arr[j]); } } swap(&arr[i + 1], &arr[high]); return (i + 1); } void quickSort(int arr[], int low, int high) //proper sorting algorithm { if (low < high) { int pi = partition(arr, low, high); quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } void fb(int m, int n, int a[][n]) //your function { int i, j, tmp = 0; int *flatten = (int *)calloc(m*n, sizeof(int)); //dynamically allocated 1D array filled with zeros for(i=0;i<m;i++) a[i][0]--; for(i=0;i<m;i++) for(j=0;j<n;j++) { flatten[tmp] = a[i][j]; tmp++; } quickSort(flatten, 0, (m*n)-1); tmp = 0; for(i=0;i<m;i++) for(j=0;j<n;j++) { a[i][j] = flatten[tmp]; tmp++; printf("%d ", a[i][j]); } } int main() { int m=4, n=2; int a[4][2]={{3,19}, {80,100}, {11,33}, {18,80}}; fb(m,n,a); 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