fork download
  1. #include <stdio.h>
  2.  
  3. int cmp(int x,int y){
  4. return x>y;
  5. }
  6.  
  7. void swap(int *x,int*y){
  8. int tem=*x;
  9. *x=*y;
  10. *y=tem;
  11. }
  12. int main(void) {
  13. int a[]={3,1,4,1,5,9,2,6,5};
  14. size_t n=sizeof a/sizeof a[0];
  15.  
  16. int count=0;
  17. for(size_t i=0;i<n-1;i++){
  18. for(size_t j=0;j<n-1-i;j++){
  19. if(cmp(a[j],a[j+1])){
  20. swap(&a[j],&a[j+1]);
  21. count++;
  22. }
  23. }
  24. if(count==0){
  25. break;
  26. }
  27. }
  28. for(size_t i=0;i<n;i++){
  29. printf("%d",a[i]);
  30. }
  31. printf("\n");
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5356KB
stdin
Standard input is empty
stdout
112345569