Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void bub(char* s){
  6. int i, j, n=strlen(s);
  7. char tmp;
  8. char st[n];
  9. strcpy(st,s);
  10. for(i=n-1;i>0;i--){
  11.     for(j=0;j<i;j++){
  12.         if(st[j]>st[j+1]){
  13.             tmp=st[j];
  14.             st[j]=st[j+1];
  15.             st[j+1]=tmp;
  16.         }
  17.     }
  18. }
  19. printf("%s\n", st);
  20. }
  21.  
  22. int main(){
  23. int n;
  24. printf("введите размер массива\n");
  25. scanf("%i", &n);
  26. char* str=malloc(sizeof (n));
  27. printf("введите массив символов меньший или равный %i\n", n-1);
  28. fgets(str,n-1,stdin);
  29. int i;
  30. printf("%s\n", str);
  31. bub(str);
  32. return (0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement