Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define rozmiar 10
  4. #define epsilon 1e-5
  5.  
  6.  
  7. void sortowanie(double*,int);
  8. void zamiana(double*,double*);
  9.  
  10. int main(){
  11. double tab[rozmiar]={1,204,17,0,15,166,2,13,344,3211};
  12.  
  13. for(int i=0;i<rozmiar;i++)printf("%.2lf ",tab[i]);
  14. printf("\n");
  15.  
  16. sortowanie(tab,rozmiar);
  17.  
  18. for(int i=0;i<rozmiar;i++)printf("%.2lf ",tab[i]);
  19. printf("\n");
  20.  
  21. return 0;
  22. }
  23.  
  24. void sortowanie(double*tab,int n){
  25. int end=0;
  26. while(!end){
  27. end=1;
  28. for(int i=0;i<n-1;i++){
  29. if(*(tab+i)-*(tab+i+1)>epsilon){
  30. zamiana(tab+i,tab+i+1);
  31. end=0;
  32. }
  33. }
  34. }
  35.  
  36. }
  37.  
  38. void zamiana(double*a,double*b){
  39. double temp=*a;
  40. *a=*b;
  41. *b=temp;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement