Advertisement
GarikK

Untitled

Jan 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1.  
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5.  
  6.  
  7. using namespace std;
  8. int GetMax(int x[], int arraySize)
  9. {
  10.     int currentMax = 0;
  11.     for (int i = 0; i < arraySize; i++)
  12.     {
  13.         int currentArrayElement = x[i];
  14.         if (currentMax < currentArrayElement)
  15.         {
  16.             currentMax = currentArrayElement;
  17.         }
  18.     }
  19.     return currentMax;
  20. }
  21. void SortArray(int x[], int arraySize)
  22. {
  23.     bool isOk = true;
  24.     do
  25.     {
  26.         isOk = true;
  27.         for (int i = 0; i < arraySize - 1; i++)
  28.         {
  29.             if (x[i] > x[i + 1])
  30.             {
  31.                 int tmpX = x[i];
  32.                 x[i] = x[i + 1];
  33.                 x[i + 1] = tmpX;
  34.                 isOk = false;
  35.             }
  36.         }
  37.     } while (!isOk);
  38. }
  39. int main()
  40. {
  41.     const int arraySize = 5;
  42.     int a[arraySize] = { 11,25,23,14,5 };
  43.     //int max = GetMax(a, arraySize);
  44.     SortArray(a, arraySize);
  45.     //cout << "Max value is - " << max << "\n";
  46.     for (int i = 0; i < arraySize; i++)
  47.     {
  48.         cout << a[i] << "\t";
  49.     }
  50.     cout << "\n";
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement