[ create a new paste ] login | about

Link: http://codepad.org/5INkkhNS    [ raw code | output | fork ]

C, pasted on Oct 26:
#include <stdio.h>
int main() {
  static int a[] = {8, 5, 12, 7, 9};
  static int b[] = {0, 0, 0, 0, 0};
  int n, m, i, min, idx;
  n = sizeof(a) / sizeof(int);
  m = 0;
  while (n > 0) {
    min = a[0];
    idx = 0;
    for (i = 1; i < n; i++)
      if (a[i] < min) {
        min = a[i];
        idx = i;
      }
    b[m] = min;
    m++;
    n--;
    a[idx] = a[n];
  }
  for (i = 0; i < sizeof(a) / sizeof(int); i++)
    printf("%d, ", b[i]);
  return 0;
}
/* end */


Output:
1
5, 7, 8, 9, 12, 


Create a new paste based on this one


Comments: