Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. void swap(int *a, int *b)
  4. {
  5. int temp =*a;
  6. *a = *b;
  7. *b = temp;
  8. }
  9. void bubblesort(int s[], int n)
  10. {
  11. int k,m;
  12. for(k=0;k<n-1;k++)
  13. {
  14. for(m=0;m<n-k-1;m++)
  15. {
  16. if(s[m]>s[m+1])
  17. {
  18. swap(s[m],s[m+1]);
  19. }
  20. }
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. int i,j,i_max=0,s[100];
  27. char c[100];
  28. scanf("%s",&c);
  29. i_max=strlen(c);
  30.  
  31. for(i=0,j=0;i<i_max;i+=2,j++)
  32. {
  33. s[j]=c[i]-48;
  34. }
  35. s[j]='\0';
  36. bubblesort(s,i_max);
  37. for (i=0;i<(i_max+1)/2;i++)
  38. {
  39. printf("%d ",s[i]);
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement