uikolas

C++ rikiavimas

Sep 17th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Rikiavimas(int A[], int n);
  6.  
  7. int main(){
  8. int A[5] = {1, 33, 45, 89, 5};
  9. int n = 5;
  10.  
  11. Rikiavimas(A, n);
  12.  
  13. for(int i = 0; i < n; i++)
  14.     cout << A[i] << endl;
  15.  
  16. return 0;
  17. }
  18.  
  19. void Rikiavimas(int A[], int n){
  20.     int k;
  21.     for(int i = 0; i < n; i++){
  22.         for(int j = 0; j < n - 1; j++){
  23.             if(A[j] > A[j+1]){
  24.                 k = A[j];
  25.                 A[j] = A[j+1];
  26.                 A[j+1] = k;
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment