fork download
  1. /*
  2.   Copyright 2011 Marek "p2004a" Rusinowski
  3.   Bubble sort
  4. */
  5. #include <cstdio>
  6.  
  7. #define MAXN 1000000
  8.  
  9. int array[MAXN];
  10.  
  11. int main() {
  12. int n;
  13. scanf("%d", &n);
  14. for (int i = 0; i < n; ++i) {
  15. scanf("%d", &array[i]);
  16. }
  17. for (int i = 0; i < n; ++i) {
  18. for (int j = 0; j < (n - i) - 1; ++j) {
  19. if (array[j] > array[j + 1]) {
  20. int tmp = array[j];
  21. array[j] = array[j + 1];
  22. array[j + 1] = tmp;
  23. }
  24. }
  25. }
  26. for (int i = 0; i < n; ++i) {
  27. printf("%d ", array[i]);
  28. }
  29. printf("\n");
  30. return 0;
  31. }
  32.  
stdin
10
10 9 8 7 6 5 1 3 2 4
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
1 2 3 4 5 6 7 8 9 10