Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <unistd.h>
  4. using namespace std;
  5.  
  6. void swap_(int & a, int & b) {
  7.     int c = a;
  8.     a = b;
  9.     b = c;
  10. }
  11.  
  12. int main (){
  13.     int arr[5];
  14.     arr[0]=9; arr[1]=7; arr[4]=7;arr[3]=8; arr[2]=2;
  15.     int j;
  16.     j=arr[0];
  17.     for(int i = 0; i < 5; i++) {
  18.         cout << arr[i] << " ";
  19.     }
  20.     cout << endl;
  21.     for(int i = 0; i < 5; i++) {
  22.         if (arr[i] > j) {
  23.             j = arr[i];
  24.         }
  25.     }
  26.     cout << j << endl;
  27.     for(int j = 0; j < 5; j++) {
  28.         for(int i = 0; i < 4; i++) {
  29.             if (arr[i] > arr[i+1]) {
  30.                 swap_(arr[i], arr[i+1]);
  31.             }
  32.         }
  33.     }
  34.     for(int i = 0; i < 5; i++) {
  35.         cout << arr[i] << " ";
  36.     }
  37.     cout << endl;
  38.     /*
  39.     for (int t=0;t<5;t++){
  40.         if(t < arr[t]){
  41.            j=arr[t];
  42.  
  43.         }
  44.  
  45.     }
  46.     cout << j <<endl;
  47.     */
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement