Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. double apsolutna(double n)
  6. {
  7. if(n<0) return -n;
  8. else return n;
  9. }
  10.  
  11.  
  12. void sort(double *niz,int n)
  13. {
  14. int i,j;
  15. double tmp;
  16.  
  17. for(i=0;i<n;i++)
  18. for(j=i+1;j<n;j++)
  19. if(apsolutna(niz[i])>apsolutna(niz[j]))
  20. {
  21. tmp=niz[i];
  22. niz[i]=niz[j];
  23. niz[j]=tmp;
  24. }
  25.  
  26.  
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32. double *niz,x;
  33. int n=0,i;
  34.  
  35.  
  36. while(1)
  37. {
  38. printf("Ucitaj realan broj");
  39. scanf("%lf",&x);
  40. niz=(double*)malloc(++n*sizeof(double));
  41. if(x<0) break;
  42. niz[n-1]=x;
  43.  
  44. }
  45.  
  46. sort(niz,n);
  47.  
  48. for(i=0;i<n;i++)
  49. printf("%lf\n",niz[i]);
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement