fork download
  1. #include <stdio.h>
  2. #define MAX 5
  3. int main(){
  4. int data[MAX] = {5,1,4,3,2};
  5. int temp = 0;
  6. printf("5, 1, 4, 3, 2\n");
  7. for(int i=0;i<MAX-1;i++){
  8. for(int j=0;j<MAX-1-i;j++){
  9. if(data[j]>data[j+1]){
  10. temp = data[j];
  11. data[j] = data[j+1];
  12. data[j+1] = temp;
  13.  
  14. }
  15. }
  16. }
  17. printf("버블 정렬 결과 \n");
  18. for(int i=0;i<MAX-1;i++){
  19. printf("%d/t", data[i]);
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
5, 1, 4, 3, 2
버블 정렬 결과 
1/t2/t3/t4/t