fork download
  1. #include <iostream>
  2.  
  3. template <class T>void sort(T *p, int n) {
  4. register int i, j;
  5. T t;
  6. for(i = 1; i < n; ++i)
  7. for (j = n - 1; j >= i; j--) {
  8. if(p[j-1]>p[j]) {
  9. t = p[j-1];
  10. p[j-1] = p[j];
  11. p[j] = t;
  12. }
  13. }
  14. }
  15. int main(int argc, char const *argv[]) {
  16.  
  17. char *s_arr[10] = {"an","cc","bc","gc","xc","acc","aac","eec","rrp","yxz"};
  18. char c_arr[10] = {'a','c','b','g','x','a','c','c','p','y'};
  19. int i_arr[10] = {1,2,3,4,5,6,7,8,0,9};
  20. double d_arr[10] = {2,3,-4.44,4,51.2,6,7,8.3,0,9.2};
  21. float f_arr[10] = {-2,3,-4.44,4.78,-51.2,6,7,8.3,0,9.2};
  22. int count = sizeof(i_arr)/sizeof(i_arr[0]);
  23. for (size_t i = 0; i < count; i++) {
  24. //printf("%.3lf ",i_arr[i]);
  25. //printf("%d ",i_arr[i]);
  26. //printf("%c ",c_arr[i]);
  27. printf("%.2f ",f_arr[i]);
  28. //printf("%s ",s_arr[i]);
  29. }
  30.  
  31. sort(f_arr, count);
  32.  
  33. printf("%s\n","");
  34. for (size_t i = 0; i < count; i++) {
  35. //printf("%.3lf ",i_arr[i]);
  36. //printf("%d ",i_arr[i]);
  37. //printf("%c ",c_arr[i]);
  38. printf("%.2f ",f_arr[i]);
  39. //printf("%s ",s_arr[i]);
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5456KB
stdin
Standard input is empty
stdout
-2.00 3.00 -4.44 4.78 -51.20 6.00 7.00 8.30 0.00 9.20 
-51.20 -4.44 -2.00 0.00 3.00 4.78 6.00 7.00 8.30 9.20