Advertisement
Guest User

Sortowanie min max

a guest
Jan 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. const int MAX= 100;
  5.  
  6. void dane(int &n)
  7. {
  8.     cout<<"Podaj liczbe elementow tablicy:"<<endl;
  9.     cin>>n;
  10. }
  11.  
  12. void wczytaj(double T[], int n)
  13. {
  14.     cout<<"podaj elementy tablicy"<<endl;
  15.     for(int i=0;i<n;i++)
  16.     {
  17.         cout<<"T["<<i<<"] = ";
  18.         cin>>T[i];
  19.     }
  20. }
  21.  
  22. void wyswietl(double T[], int n)
  23. {
  24.     cout<<"wczytna tablica:"<<endl;
  25.     for(int i=0;i<n;i++) cout<<T[i]<<"\t";
  26.     cout<<endl;
  27. }
  28.  
  29. void sortuj(double T[], int n)
  30. {
  31.     double pom;
  32.     for(int j=n-1;j>0;j--)
  33.         for(int i=0;i<j;i++)
  34.             if(T[i]>T[i+1])
  35.             {
  36.                 pom=T[i];
  37.                 T[i]=T[i+1];
  38.                 T[i+1]=pom;
  39.             }
  40. }
  41. int main()
  42. {
  43.     double T[MAX];
  44.     int n;
  45.     dane(n);
  46.     wczytaj(T,n);
  47.     wyswietl(T,n);
  48.     sortuj(T,n);
  49.     cout<<"Liczba najmniejsza"<<endl;
  50.     cout<<T[0]<<endl;
  51.     cout<<"Liczba najwieksza"<<endl;
  52.     cout<<T[n-1]<<endl;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement